Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
MS translator request not authorized

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

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your screenshot shows an app registration configuration page in Azure Active Directory - this is something entirely different. What you want is creating a Translator resource and then take one of the keys from the "Keys and Endpoints" menu:

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar

0

With the following adjustments, the code should work:

  • use in my_token one of the subscription keys under "Azure portal > Translator resource > Keys and Endpoint > Key 1 or Key 2"
  • check the region for Ocp-Apim-Subscription-Region (also required for authentication), use the term under "Azure portal > Translator resource > Keys and Endpoint > Region"
  • insert in apiurl: &from=en&to=de
  • change data in: JSON.stringify([{ 'text': 'Test simple text' }])

var apiurl = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de';
var my_token = 'xxxxxx'; // subscription key
jQuery.ajax({
    url: apiurl,
    dataType: "json",
    jsonp: "oncomplete",
    crossDomain: true,
    context: this,
    data: JSON.stringify([{ 'text': 'Test simple text' }]),
    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);
    }
});

function uuid() {
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  );
}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda