shawee
shawee

Reputation: 61

Bing Search API for iOS

I'd like to use Bing IMAGE API in PHP, JS or ObjC, but classes and properties like http://msdn.microsoft.com/en-us/library/dd250939.aspx seem only available with C# or VB, is that right ?

I'd just like to get image search JSON result, specifying width and height... Looks not possible from GET url : api.bing.net/xml.aspx?Appid=XXXXXXXXXXXXXXXXXXXXX&query=sushi&sources=image I tried to insert &size=small or &width=300 but doesn't send any change back.

I may use API with ObjC iOS and http://ibing.codeplex.com/ indeed implement WIDTH and HEIGHT properties but just as response information, not request parameters.

Upvotes: 1

Views: 1730

Answers (1)

Dr.Kameleon
Dr.Kameleon

Reputation: 22820

This is how I would go about it :

  1. Get a PHP Script to do the job on your server (this works for me for regular API Search, but should work for image search as well (perhaps, with some modifications...)) :

    function getOnePageUrls($querystr, $country="com", $page=1)
    {
        $markets = array(
            "com" => "en-US",
            "co.uk" => "en-GB",
            "ru" => "ru-RU",
            "de" => "de-DE",
            "fr" => "fr-FR",
            "es" => "es-ES"
        );
    
        $market = $markets[$country];
    
        if ($page==1) $offset = 0;
        else $offset = (($page-1)*50)+1;
    
        $appID = "XXXXXXXXXXXXXXXXXXXXXXXXX";  // your Bing App ID
        $searchstr = "http://api.search.live.net/json.aspx?Appid=$appID&query=$querystr&sources=web&market=$market&web.count=50&web.offset=$offset";
    
        $json = file_get_contents($searchstr);
    
        $results = json_decode($json);
        $results = $results->SearchResponse->Web->Results;
    
        foreach ($results as $result)
        {
            $response[] = $result->DisplayUrl;
        }
    
        return $response;
    }
    
  2. Get the response in your Objective-C code, using a simple GET request

And that's it! :-)

Upvotes: 1

Related Questions