rma
rma

Reputation: 1958

Bing News API Error 403 - InsufficientAuthorization

I've been trying to work on a project with angularJS and the bing search api's v7. However, whenever I make a http request to the provided URL ("https://api.cognitive.microsoft.com/bing/v7.0/news?") I get an error 403 response with error message: "Insufficient Authorization". I looked at the Microsoft docs and they said the error could be caused "if the subscription key has been disabled or has expired."

However, I just got this key today. It seems odd that it would have expired or already been deactivated. Not sure what could be going on here.

Relevant code is

    var params = {
        // Bing news search request parameters
        "q": "query",
        "count": "3",
        "offset": "0",
        "mkt": "en-us",
        "safesearch": "Moderate"
    };
    $http({
        method: 'GET',
        url: "https://api.cognitive.microsoft.com/bing/v7.0/news?"+ $httpParamSerializer(params),
        headers:{"Ocp-Apim-Subscription-Key":"my_subscription key"}
    }).then(
        function successCallback(response) {
            console.log('success');
            console.log(response);

        }, function errorCallback(response) {
            console.log('error');
            console.log(response);
        });

What could be causing this issue? If it's a problem with the API, are there any other good news-gathering API's available?

Upvotes: 0

Views: 748

Answers (2)

Ronak
Ronak

Reputation: 736

https://api.cognitive.microsoft.com/bing/v7.0/news is a different end-point. It is meant for category news search: https://dev.cognitive.microsoft.com/docs/services/e5e22123c5d24f1081f63af1548defa1/operations/56f02400dbe2d91900c68553.

The https://api.cognitive.microsoft.com/bing/v7.0/news/search defined here: https://dev.cognitive.microsoft.com/docs/services/e5e22123c5d24f1081f63af1548defa1/operations/56b449fbcf5ff81038d15cdf is the correct end-point for getting news for a given query.

Both the endpoints work for their respective usecases - the one without "/search" for category news (optional "category" parameter) and one with "/search" for the intended usecase here.

Upvotes: 0

Martin van Delft
Martin van Delft

Reputation: 457

Why is "https://api.cognitive.microsoft.com/bing/v7.0/news" giving 403 - InsufficientAuthorization?

The v5.0 url works. The v7.0 simply won't. This seems to be Microsoft. After all it is still in preview.

On either v5.0 or 7.0 /search works. And for /trendingtopics you need to pass ?mkt= with en-US or zh-CN.

Do I need an azure account to access the API?

No, you do not need an Azure account. The API keys generated can be used in the API test from Microsoft(if available), in Postman or any other mechanism that makes the request for you.

Upvotes: 1

Related Questions