March 12, 2013 Posted by Victor in Frameworks & Tools, PHP best practice

Using Google, Bing and Flickr API to search for images

Need to show some pictures for searches, products or names and you don't have them?

I came across this problem once and I will like to share an easy solution. The solution is strickly technical, you should check the terms and conditions before using the images. Focusing just on Creative Commons-licensed photos is the safest approach.

First, to avoid any Google limitations on searching images I have integrated also Bing and Flickr, linking them when a problem appears.

The API call ussualy return an JSON (of XML) response and the functions are arranging the pictures in arrays and returns 4 pictures in a maximum 209/209 pixels format. The $group variable in the functions is used to change the pictures return.


When $group=0 you can see pictures 1->4, when $group=1, pictures 5->8, and so on.

The documentation for the API search images: http://code.google.com/apis/imagesearch/v1/jsondevguide.html http://www.codeproject.com/KB/cs/BingSearch.aspx http://www.flickr.com/services/api/explore/flickr.photos.search


This is how we call the function:

include 'google.php';
$Google = new Google;
$pictures = $Google->search($query, $group);

You can download all the PHP sources (the images search classes) here

Click to share thisClick to share this