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

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

主站蜘蛛池模板: 992tv又爽又黄的免费视频 | 经典国产乱子伦精品视频 | 久久精品国产自在一线 | 色播视频在线 | 欧美大成色www永久网站 | 久久精品网| 成人婷婷| 一级做a级爰片性色毛片视频 | 日韩一二三 | 黄色网址免费在线 | 国产精品嫩草影院在线观看免费 | 亚洲精品香蕉婷婷在线观看 | 八月丁香婷婷 | 欧美激情图片区 | 欧美亚洲国产精品 | 美女很黄免费 | 一区二区三区视频免费 | 狠狠婷婷| 92看片淫黄大片看国产片 | 在线视频 亚洲 | 普通话对白国产情侣自啪 | 国产一区视频在线免费观看 | 青草五月天 | 色在线观看视频 | 久久91精品国产91 | 看全色黄大色大片免费久久 | 中文字幕精品亚洲无线码二区 | 四虎中文 | 玖玖爱国产 | 狠狠色丁香久久综合五月 | 国产玖玖 | 中文字幕亚洲一区二区va在线 | 久久99亚洲综合精品首页 | 激情视频网址 | 一级做a爰性色毛片 | 欧美日韩亚洲精品国产色 | avav在线精品 | 欧美一区二区三区gg高清影视 | 欧美综合色另类图片区 | 国产成人亚洲精品无广告 | 国产精品天天影视久久综合网 |