I'm writing a web app and would like to use the Bing translation API since Google charges for theirs. I've registered on the Azure Marketplace and registered an app as well. The problem is that I haven't found out how to get the actual access token I need. I tried some AJAX calls in plunker but all of them hit a 'No 'Access-Control-Allow-Origin' header is present on the requested resource' wall. The only instructions I find on obtaining the access token are all in a different language (php, C#, Java) while I really need it to be Javascript. Is there a way to get the access token this way at all?
Currently I'm trying to call the service this way:
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
}
return xhr;
};
var xhr = createCORSRequest('POST', 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13?client_id=[CLIENT_ID_HERE]&client_secret=[CLIENT_SECRET_HERE]&scope=http://api.microsofttranslator.com&grant_type=client_credentials&');
xhr.onloadend = function(data){
alert(JSON.stringify(data));
};
xhr.send();