Search code examples
c#unity-game-engineazure-cognitive-servicesbing-news-search-api

Error 401 when accessing Bing News API v7 using from Unity


I would like to use UnityEngine.Networking and StartCoroutine() to retrieve data from Bing API in Unity/C#. I am getting Error 401 which is:

{"error":{"code":"401","message": "Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}

The url that I am attempting to call is:

https://[**MyEndpoint**]/bing/v7.0/news/trendingtopics?BingAPIs-Market=en-US&Ocp-Apim-Subscription-Key=[**KEY**]

I assume the reason for rejection is that I explicitly added Ocp-Apim-Subscription-Key header in the url but not sure %100.


Solution

  • As @jdweng indicated, you should specify your subscription key in the request header, just as below : enter image description here

    If it is necessary for you using the subscription key in the request URL,the param here should be subscription-key instead of Ocp-Apim-Subscription-Key just as below:

    enter image description here