Bing图像搜索API不起作用

时间:2018-04-16 16:00:07

标签: c# azure botframework bing-api azure-cognitive-services

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

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

在BingImageSearch方法上调试它

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

它返回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;

我在这里缺少什么?这是网址上的内容吗?

1 个答案:

答案 0 :(得分:1)

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