Bing 图片搜索 api 不工作

Bing image search api not working

您好,我正在尝试使用 Bing 图片搜索服务,并按照此处的文档进行操作 https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/csharp

当我 运行 我的代码使用行 -

在 BingImageSearch 方法上调试它时

HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result;

它 returns 一个 401 错误。这是授权错误。 我将其用于 api 调用:

const string uriBase = "https://api.cognitive.microsoft.com/bing/v7.0/images/search";
    const string accessKey = "********";

我的 accessKey 是正确的,已经在 azure 上检查过了,但我仍然收到 401 错误。 这是请求的其余代码:

// Construct the URI of the search request
        var uriQuery = uriBase + "?q=" + Uri.EscapeDataString("Puppies");
        // Perform the Web request and get the response
        WebRequest request = HttpWebRequest.Create(uriQuery);
        request.Headers["Ocp-Apim-Subscription-Key"] = accessKey;

我在这里错过了什么? url 上有什么东西吗?

我已经想通了。在 bing api 的 azure 资源上,在定价层选项下,如果您的定价层不包括图像搜索,它将不起作用。我已经为网络和视频设置了 S5 标准定价,所以将其更改为网络和图像 S3 标准并解决了它。