×

Custom Image Search API – C# (.Net) client library

How to use Custom Image Search with C# (.Net)

Use C#(.Net) client library to integrate News API into your C#(.Net)  application


public static void Test()
{
    //Replace the following string value with your valid X-RapidAPI-Key.
    string Your_X_RapidAPI_Key = "xxxxxxxxxxxxxxxxxxxxx";

    //The query parameters: (update according to your search query)
    string q = "Taylor%20Swift"; //the search query
    int pageNumber = 1; //the number of requested page
    string searchEngineId = "XXXX"; #the id of the custom search engine 

    //Perform the web request and get the response
    var response = Unirest.get(string.Format("https://custom-search.p.rapidapi.com/api/search/CustomImageSearchAPIV2?q={0}&pageNumber={1}&searchEngineId={2}", q, pageNumber, searchEngineId))
    .header("X-RapidAPI-Key", Your_X_RapidAPI_Key)
    .asJson();

     //Get the ResponseBody as a JSON
    dynamic jsonBody = JsonConvert.DeserializeObject(response.Body);

    //Get the number of items returned
    int totalCount = (int)jsonBody["totalCount"];

    //Go over each resulting item
    foreach (var image in jsonBody["value"])
    {
        //Get the image
        string imageUrl = image["url"].ToString();
        int imageHeight = (int)image["height"];
        int imageWidth = (int)image["width"];

        //Get the image thumbail
        string thumbnail = image["thumbnail"].ToString();
        int thumbnailHeight = (int)image["thumbnailHeight"];
        int thumbnailWidth = (int)image["thumbnailWidth"];

        Console.WriteLine(string.Format("imageUrl: {0}. imageHeight: {1}. imageWidth: {2}",
        imageUrl,
        imageHeight,
        imageWidth));
    }
}