problems in getting access tokens RRS feed

  • Question

  • Hello,

    After some research I discovered that the appid access to translator services is no longer supported
    and we need to get azure access token in order to access the translator service. However, it seems that there are some issues while getting the access token from an ajax call (it always ends up with a 'parsererror' message), also, there is no documentation available about how to get the access token from a pure javascript call. I solicit your help in
    this issue, find the details below.

    I'm trying to get an access token first, using this method
    type: 'POST',
    crossDomain: true,
    dataType: 'jsonp',
    contentType: 'application/x-www-form-urlencoded',
    jsonp: 'oncomplete',
    jsonpCallback: 'ajaxTranslateCallback',
    data: {
    'grant_type': encodeURIComponent('client_credentials').toString(),
    'client_id': encodeURIComponent('ed8f22b0-8ff8-4f8b-9797-44c0465e1202').toString(),
    'scope': encodeURIComponent('http://api.microsofttranslator.com')
    complete: function (request, status)
    alert('complete: ' +
    success: function (data, textStatus)
    error: function (request, a, b)
    function ajaxTranslateCallback(response) {
    alert('ajaxTranslateCallback(' +
    response + ')');

    sites , suggest that the recommended way is to host a server code to get the
    access token, this is not possible in my case as i'm going to host
    a javascript page in an MS-CRM 2011 application. is it not possible to make a
    POST call from anywhere (using only javascript) to get the access token , or
    there is some bug in my code.


    I copied the sample console application programme to generate the auth code, and provided my clientid,clientsecret parameters, it failed with this message. 

    "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel"

    Saturday, November 10, 2012 10:33 AM

All replies

  • It's definitely worth trying to find a way to do it server-side, because otherwise your Client ID and Client Secret are provided in-the-clear for anyone to steal and eat your quota. For that reason alone, we don't support JS-only calls.

    While I've never tried it directly in JS, but looking at your code, I see a couple of potential gotchas:

    1. What does encodeURIComponent do? Have you checked to see if it is encoding things correctly?

    2. I notice that you post the contents using JSON. I am not sure if that will work. My recommendation would be to first implement the code in something like ASP.NET (there's an example here: http://blogs.msdn.com/b/translation/p/gettingstarted2.aspx) and take a look at the HTTP headers it generates. Then, use JavaScript to generate headers in the same structure, and try them....


    Monday, November 12, 2012 6:03 PM