最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用PHP獲取Google AJAX Search API 數(shù)據(jù)的代碼

 更新時(shí)間:2010年03月12日 00:03:58   作者:  
用PHP獲取Google AJAX Search API 數(shù)據(jù)的代碼

http://code.google.com/apis/ajaxsearch/documentation/#fonje

復(fù)制代碼 代碼如下:

// This example request includes an optional API key which you will need to
// remove or replace with your own key.
// Read more about why it's useful to have an API key.
// The request also includes the userip parameter which provides the end
// user's IP address. Doing so will help distinguish this legitimate
// server-side traffic from traffic which doesn't come from an end-user.
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q=Paris%20Hilton&key=INSERT-YOUR-KEY&userip=USERS-IP-ADDRESS";

// 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, /* Enter the URL of your site here */);
$body = curl_exec($ch);
curl_close($ch);

// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...

API KEY 申請(qǐng)地址:
http://code.google.com/apis/ajaxsearch/signup.html

由此,我們可以寫個(gè)函數(shù)像這樣
復(fù)制代碼 代碼如下:

function google_search_api($args, $referer = 'http://www.fzitv.net/', $endpoint = 'web'){
$url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint;
if ( !array_key_exists('v', $args) )
$args['v'] = '1.0';
$url .= '?'.http_build_query($args, '', '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
return json_decode($body);
}

// 使用示例
$rez = google_search_api(array(
'q' => '21andy.com', // 查詢內(nèi)容
'key' => '你申請(qǐng)到的API KEY',
'userip' => '你的IP地址',
));
header('Content-type: text/html; charset=utf-8;');
echo '<xmp>';
print_r($rez);
echo '</xmp>';

相關(guān)文章

最新評(píng)論

天等县| 佛学| 澎湖县| 清水河县| 赣州市| 广河县| 霍州市| 都江堰市| 仲巴县| 称多县| 马龙县| 郑州市| 西畴县| 自贡市| 长乐市| 突泉县| 汕头市| 滦平县| 绥芬河市| 淮北市| 盐源县| 曲水县| 上虞市| 巴楚县| 灵丘县| 琼中| 双柏县| 凤庆县| 屯门区| 介休市| 汝城县| 泗洪县| 茌平县| 来宾市| 黄冈市| 来安县| 雷州市| 英吉沙县| 柳州市| 井冈山市| 乃东县|