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!");
}
}
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
© 2024 OneMinuteCode. All rights reserved.