Bing custom search get the next 10 results ASP.NET C#

261 views Asked by At

I was able to connect and setup Bing custom search. My question is how to get the following 10 results? And is it possible to get more than 10 results in one request?

    var subscriptionKey = "My Key";
    var customConfigId = "My ID";
    var searchTerm = "test";

    var url = "https://api.bing.microsoft.com/v7.0/custom/search?q=" + searchTerm + "&customconfig=" + customConfigId + "&mkt=en-US";

    var client = new HttpClient();
    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

    var httpResponseMessage = client.GetAsync(url).Result;
    var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result;
    BingCustomSearchResponse response = JsonConvert.DeserializeObject<BingCustomSearchResponse>(responseContent);

    for (int i = 0; i < response.webPages.value.Length; i++)
    {
        var webPage = response.webPages.value[i];

    }
2

There are 2 answers

0
BingAPIs On
0
OneCricketeer On

There is a count query parameter that defaults to 10

To paginate, use offset, in increments of count

refer docs - https://learn.microsoft.com/en-us/bing/search-apis/bing-custom-search/quickstarts/rest/csharp