Home > OS >  MS translator request not authorized
MS translator request not authorized

Time:11-19

I have this simple code to get translation:

    var apiurl = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0';
    var my_token = 'xxxxxx'; // my sekret key
        jQuery.ajax({
            url: apiurl,
            dataType: "json",
            jsonp: "oncomplete",
            crossDomain: true,
            context: this,
            data: {
                text: 'Test simple text',
                from: 'en',
                to: 'de'
            },
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Ocp-Apim-Subscription-Key', my_token);
                xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8');
                xhr.setRequestHeader('X-ClientTraceId', uuid());
                xhr.setRequestHeader('Ocp-Apim-Subscription-Region', 'westeurope');
            },
            contentType: "application/json; charset=UTF-8",
            type: 'POST',
            success: function (msg) {
                console.log(msg);
            },
            complete: function (msg) {
            },
            error: function (e) {
                console.log(e);
            }
        });

But I got always error 401000 The request is not authorized because credentials are missing or invalid.

I used secred ID from picture. enter image description here

CodePudding user response:

Your screenshot shows an app registration configuration page in Azure Active Directory - this is something entirely different. What you want is enter image description here

  • Related