简体   繁体   中英

Bing Image Search API results exipres after some time

I am implementing Bing Image Search API in php. I know that Bing API has been changed and now we have to involve that windows azure marketplace thing in-order to use the Bing Image Search API.

I have done that, which means i have opted for a free Bing Search Api subscription which gives me around 5000 transaction per month. Its going all good but the thing is the result which is being fetched is tend to get expired after say 1 month.

Here is the code i am using :

     $key = "cricket";
     // Replace this value with your account key
     $accountKey = 'WEGUEed3yF9CI6ZzVblKD0HoMRG3/rOELkCda9VYsuk=';
     $ServiceRootURL =  'https://api.datamarket.azure.com/Bing/Search/';  
     $WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';

     $request = $WebSearchURL . urlencode( '\'' . $key . '\'');

     $process = curl_init($request);
     curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($process, CURLOPT_USERPWD,  $accountKey . ":" . $accountKey);
     curl_setopt($process, CURLOPT_TIMEOUT, 30);
     curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
     $response = curl_exec($process);

     $jsonobj = json_decode($response);

     echo('<ul ID="resultList">');

      foreach($jsonobj->d->results as $value)
     {                        
    echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">'); 
    echo('<img src="' . $value->Thumbnail->MediaUrl. '"></li>'); 
    }

     echo("</ul>");

On running this program i am getting the results, I am getting the image source. But the thing is the image source doesn't seems to be a real image source i mean the URL is something like this :

    http://ts4.mm.bing.net/th?id=HN.608026386931518543&pid=15.1

Also this link is expires after a month or so .... Initally i was able to see the image when clicking on the link but it expired after a month and now i can only see a greyish camera with a cross on it which means that the image source has been expired i guess.

If you can let me how can i restrict this thing and also is anything needs to done on the windows azure market place end to get things working for me .

Any help will be appreciated

Thanks

Fix for original images.

On the line 22, where are interpreted received and parsed JSON data

echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');

there is a mistake from Bing.

You can just replace $value->MediaURL for $value->MediaUrl and you can get acquire access to original image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM