Understanding the Translator Text API

Asked 2 years ago, Updated 2 years ago, 136 views

We are currently working on an application using the Translator Text API.
I am working on Unity 2017.2, but
Error retrieving token for API use.
Error Description: Access denied due to missing subscription key.Make sure to include subscription key when making requests to an API

I've tried all the methods written here, but they don't work.
https://blogs.msdn.microsoft.com/kwill/2017/05/17/http-401-access-denied-when-calling-azure-cognitive-services-apis/

Is the implementation method wrong?
If you know the solution, please help me.

This is my code:

private IEnumerator GetAccessTokenForTranslation()
{

        US>string subscriptionKey=<my key>;

        string url = "http://api.cognitive.microsoft.com/sts/v1.0/issueToken";

        List<IMultipartFormSection>formData=newList<IMultipartFormSection>();;
        formData.Add(new MultipartFormDataSection("Content-Type", "application/json"));
        formData.Add(new MultipartFormDataSection("Accept", "application/jwt"));
        formData.Add(new MultipartFormFileSection("Ocp-Apim-Subscription-Key", subscriptionKey));

        UnityWebRequest www=UnityWebRequest.Post(url,formData);
        yield return wwww.SendWebRequest();

        if(www.isNetworkError||www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {
            Debug.Log("Form upload complete!");
        }

}

unity3d api azure

2022-09-30 21:27

1 Answers

The Ocp-Apim-Subscription-Key should be included in the request header instead of as form data.

English Stackoverflow Related Questions (JavaScript Example)
https://stackoverflow.com/a/42467976/2322778


2022-09-30 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.