复制代码 代码如下:
// 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 uful to have an api key.
// the request also includes the urip parameter which provides the end
// ur’s ip address. doing so will help distinguish this legitimate
// rver-side traffic from traffic which doesn’t come from an end-ur.
$url = “http://ajax.googleapis.com/ajax/rvices/arch/web?v=1.0&”
. “q=paris%20hilton&key=inrt-your-key&urip=urs-i什么是法向量p-address”;
// ndrequest
// note how referer is t manually
$ch = curl_init();
curl_topt($ch, curlopt_url, $url);
curl_t安培力方向的判断opt($ch, curlopt_returntransfer, 1);
curl_topt($ch, curlopt_referer, /* enter the url of yo女性英文名大全ur site here */);
$body = curl_exec($ch);
curl_clo($ch);
// now, process the json string
$json = json_decode($body);
// now have some fun with the results…
api key 申请地址:
由此,我们可以写个函数像这样
复制代码 代码如下:
function google_arch_api($args, $referer = ‘//www.jb51.net/’, $endpoint = ‘web’){
$url = “http://ajax.googleapis.com/ajax/rvices/arch/”.$endpoint;
if ( !array_key_exists(‘v’, $args) )
$args[‘v’] = ‘1剪纸方法.0’;
$url .= ‘?’.http_build_query($args, ”, ‘&’);
$ch = curl_init();
curl_庄周家贫topt($ch, curlopt_url, $url);
curl_topt($ch, curlopt_returntransfer, 1);
curl_topt($ch, curlopt_referer, $referer);
$body = curl_exec($ch);
curl_clo($ch);
return json_decode($body);
}
// 使用示例
$rez = google_arch_api(array(
‘q’ => ’21andy.com’, // 查询内容
‘key’ => ‘你申请到的api key’,
‘urip’ => ‘你的ip地址’,
));
header(‘content-type: text/html; chart=utf-8;’);
echo ‘<xmp>’;
print_r($rez);
echo ‘</xmp>’;
本文发布于:2023-04-06 13:47:00,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/36a0a87c0fe077859af82bdde25c3035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:用PHP获取Google AJAX Search API 数据的代码.doc
本文 PDF 下载地址:用PHP获取Google AJAX Search API 数据的代码.pdf
留言与评论(共有 0 条评论) |