我试图用CURL将我的PHP脚本连接到google -它连接得很好--但是当我传递API键时,它说它是无效的,下面是一些我用来获取统计数据的代码…
<?php
$url = 'https://maps.google.com/maps/api/geocode/json?address={ADDRESS}&sensor=false&key={MY_KEY}';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($cURL);
curl_close($cURL);
?>我尝试在https://code.google.com/apis/console/的Google页面上为服务器(由IP地址设置)和浏览器(由域名设置)配置API密钥
我遇到的问题是,每次发送请求时,都会收到返回JSON的消息,上面写着:
stdClass Object (
[error_message] => This site or IP is not authorized to use this API key.
[results] => Array (
)
[status] => REQUEST_DENIED
)如果我试图在所涉计算机上的网页浏览器中转到url ( https://maps.google.com/maps/api/geocode/json?address=The%20White%20House,%20Washington&sensor=false&key={MY_KEY} ),就会遇到同样的问题:
{
"error_message" : "This site or IP is not authorized to use this API key.",
"results" : [],
"status" : "REQUEST_DENIED"
}服务器类型:
提前感谢您的帮助!
发布于 2013-12-11 18:48:35
使用google并不需要API密钥。这是一个令人困惑的错误信息,谷歌答复在这种情况下。只要从您的URL中删除'&key={MY_KEY}',就可以了。
发布于 2015-08-05 00:57:27
您可以在mysql.every时间内创建表位置,然后将请求.insert发送到数据库。之后,可以在数据库中使用计数记录来计数请求。我使用了此解决方案
https://stackoverflow.com/questions/20526091
复制相似问题