Bing 新闻 API 错误 403 - InsufficientAuthorization

Bing News API Error 403 - InsufficientAuthorization

我一直在尝试使用 angularJS 和 bing 搜索 api 的 v7 进行一个项目。但是,每当我向提供的 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 发出 http 请求时,他们说错误可能是 "if the subscription key has been disabled or has expired."

不过,我今天才拿到这把钥匙。它已经过期或已经被停用,这似乎很奇怪。不确定这里会发生什么。

相关代码为

    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);
        });

是什么导致了这个问题?如果是 API 的问题,还有其他好消息收集 API 可用吗?

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

v5.0 url 有效。 v7.0 根本不会。这似乎是微软。 毕竟它还在预览中。

在 v5.0 或 7.0 /search 上有效。 对于 /trendingtopics,您需要通过 ?mkt=en-USzh-CN.

Do I need an azure account to access the API?

不,您不需要 Azure 帐户。生成的 API 密钥可用于 API test from Microsoft(如果可用)、Postman 或任何其他为您发出请求的机制。

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.

https://api.cognitive.microsoft.com/bing/v7.0/news/search defined here: https://dev.cognitive.microsoft.com/docs/services/e5e22123c5d24f1081f63af1548defa1/operations/56b449fbcf5ff81038d15cdf 是为给定查询获取新闻的正确终点。

这两个端点都适用于各自的用例 - 一个没有“/search”的类别新闻(可选 "category" 参数)和一个带有“/search”的预期用例。