首頁  >  文章  >  後端開發  >  PHP访问Google Search API的方法,googleapi_PHP教程

PHP访问Google Search API的方法,googleapi_PHP教程

WBOY
WBOY原創
2016-07-13 10:05:17851瀏覽

PHP访问Google Search API的方法,googleapi

本文实例讲述了PHP访问Google Search API的方法。分享给大家供大家参考。具体如下:

这段代码段演示了如何从php向AJAX搜索API发送请求。请注意,此示例假定使用 PHP 5.2。对于较早安装的 PHP,请参考对应的官方注释。

具体代码如下:
复制代码 代码如下:$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Paris%20Hilton";
 
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.mysite.com/index.html");
$body = curl_exec($ch);
curl_close($ch);
 
// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/963847.htmlTechArticlePHP访问Google Search API的方法,googleapi 本文实例讲述了PHP访问Google Search API的方法。分享给大家供大家参考。具体如下: 这段代码段演示了如...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn