【发布时间】:2013-12-11 17:35:47
【问题描述】:
我正在尝试使用 CURL 将我的 PHP 脚本连接到谷歌地图 API,它连接良好,但是当我传递 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);
?>
我已尝试在 Google API 页面https://code.google.com/apis/console/ 上为服务器(由 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"
}
服务器类型:
- 操作系统: Windows Server 2008 R2 x64
- 服务器: UwAmp 2.2.1
- PHP: 5.4.15
- MySQL: 5.6.11
提前感谢您的帮助!
【问题讨论】:
标签: php json google-maps curl geocoding