一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

用PHP獲取Google AJAX Search API 數據的代碼

http://code.google.com/apis/ajaxsearch/documentation/#fonje
復制代碼 代碼如下:
// 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 申請地址:
http://code.google.com/apis/ajaxsearch/signup.html

由此,我們可以寫個函數像這樣
復制代碼 代碼如下:
function google_search_api($args, $referer = 'http://www.jb51.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', // 查詢內容
'key' => '你申請到的API KEY',
'userip' => '你的IP地址',
));
header('Content-type: text/html; charset=utf-8;');
echo '<xmp>';
print_r($rez);
echo '</xmp>';

php技術用PHP獲取Google AJAX Search API 數據的代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 色哟哟视频在线观看 | 自偷自拍亚洲欧美清纯唯美 | 欧色视频| 激情视频图片小说qvdo | 视频国产在线 | 欧美大陆| 国产午夜精品一区二区 | 国内一级特黄女人精品毛片 | 国内精品久久久久久影院8f | 亚洲香蕉网久久综合影院3p | 中文字幕一区二区在线播放 | 天天综合网天天综合色不卡 | 中文字幕精品视频在线 | 欧美成人免费午夜影视 | 色综合久久伊人 | 一区二区三区视频免费 | 欧美精品成人一区二区视频一 | www日本在线观看 | 一本色道久久综合一区 | 亚洲一区二区福利视频 | 日韩在线观看中文字幕 | 久久狠狠干| 91午夜精品午夜剧场 | 日本欧美国产精品第一页久久 | 一区二区三区在线 | 99精品视频一区在线视频免费观看 | 亚洲涩网| 久久综合久久精品 | 黄频在线| 婷婷综合国产激情在线 | 国产三级国产精品国产普男人 | 久久综合久久88 | 成人欧美在线观看 | 亚洲第一区精品日韩在线播放 | 亚洲精品亚洲人成在线播放 | 国产一级又裸又黄又裸又 | 草草视频在线免费观看 | 好爽毛片一区二区三区四 | 一级毛片成人免费看免费不卡 | 手机在线观看亚洲国产精品 | 在线视频免费国产成人 |