使用Google Places API添加地点时,我收到“REQUEST_DENIED”。我搜索了以前的帖子,我很确定密钥是正确的,因为它可以用于Google商家信息搜索。
可能这与我的编码有关?这是我的PHP编码:
$jsonpost = '{
"location": {
"lat": ' .$coordinate[0] .',
"lng": ' .$coordinate[1] . '
},
"accuracy": 50,
"name": ' . $locator_name .'",
"types": ["other"],
"language": "en"
}';
$url = "https://maps.googleapis.com/maps/api/place/add/json?sensor=true&key=AIzaSyCj9yH5x6_5_Om8ebAO2pBlaqJZB-TIViY";
$results = json_decode(ProcessCurl ($url, $jsonpost), TRUE);
echo "<script>alert('Google Places submission returned " . $results["status"] ."');</script><br />";
function ProcessCurl($URL, $fieldString){ //Initiate Curl request and send back the result
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fieldString))
);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $result;
}
答案 0 :(得分:0)
根据Google API控制台帮助“只有某些API支持Android和iOS密钥,例如Google Maps Android API或适用于iOS的Google Maps SDK。” (https://developers.google.com/console/help/)。你可以在这里找到详细信息
在我的案例中,通过使用'key for bowser apps'而不是使用android / iOs键解决了问题。