Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




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:

<?php

function get_images($query){
    $url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=';
    //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);
    curl_close($curl);
    //decoding request
    $result = json_decode($data, true);

    return $result;
}

$images = get_images("cars");

echo "<pre>";
print_r($images);
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 BlogAlike.com

blog comments powered by Disqus