我想連接我的PHP腳本到谷歌地圖API使用CURL它連接好,但是當我通過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);
?>
我試圖配置我的API密鑰用於服務器(通過IP地址設置)和瀏覽器(由域名設置)的谷歌API網頁上,https://code.google.com/apis/console/
我遇到的問題是每當我發送請求時,我都會收到一條返回的JSON消息:
stdClass Object (
[error_message] => This site or IP is not authorized to use this API key.
[results] => Array (
)
[status] => REQUEST_DENIED
)
,如果我嘗試轉到在Web瀏覽器的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"
}
服務器類型:
- Ø/S: Windows Server 2008 R2 x64
- 服務器: UwAmp 2.2.1
- PHP: 5.4.15
- MySQL的: 5.6.11
在此先感謝您的幫助!
可能重複的[google maps api,提供的API密鑰無效](http://stackoverflow.com/questions/19726606/google -aps-api-the-provided-api-key-is-invalid) – geocodezip