一区二区久久-一区二区三区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 數據的代碼,轉載需保留來源!

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

主站蜘蛛池模板: 呦呦色 | 久久性色 | 国产欧美一区二区精品性色tv | 性亚洲无删减 | 色婷婷丁香六月 | 深夜福利一区 | 91在线视频免费播放 | 久久久久久91 | 国产在线精品一区二区不卡 | 91免费影视| 一区二区中文字幕 | 一区二区三区高清在线 | 激情五月五月婷婷 | 精品日本久久久久久久久久 | 免费精品一区二区三区在线观看 | 黑人巨大videos极度另类 | 久久久高清日本道免费观看 | 国产精品欧美激情在线播放 | 婷婷伊人五月 | 99视频这里有精品 | 欧美视频在线观 | 亚洲欧美7777 | 九一在线| 国产精品精品视频 | 久久伊人热精品老鸭窝 | 国产日韩欧美一区二区三区综合 | 九九视频网 | 久青草国产在线视频亚瑟影视 | 激情婷婷综合 | 美国毛片亚洲社区在线观看 | 日韩精品一级a毛片 | 日韩黄色毛片 | 无码一区二区三区视频 | 四虎在线最新永久免费 | 丁香六月天婷婷 | 色婷婷欧美 | 黄色网页在线观看 | xxxx网 | 美女张腿男人桶免费视频 | 国产成人综合精品一区 | 国产高清91 |