json - How to get Google search results displayed on a website using php? -
i'm trying googles search results displayed on webpage, i'm failing examples i've found in google docs. here i've far - not display result. ideas?
<?php $query = 'test'; $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=mykeyfromapi&q=".$query; $body = file_get_contents($url); $json = json_decode($body); for($x=0;$x<count($json->responsedata->results);$x++){ echo "<b>result ".($x+1)."</b>"; echo "<br>url: "; echo $json->responsedata->results[$x]->url; echo "<br>visibleurl: "; echo $json->responsedata->results[$x]->visibleurl; echo "<br>title: "; echo $json->responsedata->results[$x]->title; echo "<br>content: "; echo $json->responsedata->results[$x]->content; echo "<br><br>"; } ?>
you have register own project api key.
you can register following link:
https://developers.google.com/
after registered own project activate custom search api take api key , add here:
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=mykeyfromapi&q=".$query;
Comments
Post a Comment