Search code examples
c#azurebotframeworkbing-apiazure-cognitive-services

Bing image search api not working


Hi I am trying to use the Bing image search services and following the documentation from here https://learn.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/csharp

When I run my code debugging it on the BingImageSearch method with the line -

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

It returns a 401 error. It is an authorization error. I am using this for the api calls:

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

My accessKey is correct already checked on azure but I still get the 401 error. This is the rest of the code for the request:

// 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;

What am I missing here? Is it something on the url?


Solution

  • I already figured it out. On the azure resource for the bing api, under the pricing tier options if your pricing tier does not include the images search it won't work. I had it set for web and video the S5 standard pricing so changed it to the web and images S3 standard and that solved it.