• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Google image API using cURL

There are alot of tutorials on Google Image search API using javascript interface, but what if you want to do it old fashion way, using php and curl? Well here is a way to do it.

First you'll need to register for Google Search API key

Then you can use this piece of code, just don't forget to input your API key:


function get_images($query){
    $url = '';
    //enter your API key here
    $key = 'your-key-here';
    $url .= urlencode($query).'&key='.$key;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    //decoding request
    $result = json_decode($data, true);

    return $result;

$images = get_images("cars");

echo "<pre>";
echo "</pre>";


PHP curl requests return only 4 image result from 64 maximum allowed images. To retrieve more in most effective way try this Google Image PHP class

You may also be interested in:

Powered by

blog comments powered by Disqus