我有一些 PHP 代码可以向 google 地方添加一个地方,但是我收到了一个 REQUEST_DENIED 错误,我不知道为什么:
$data = array(
"location" => array("lat"=>floatval(trim($latlng[1])),"lng"=>floatval($latlng[0])),
"accuracy" => 50,
"name" => urlencode($edtName),
"types" => array(urlencode($cmbType[0]))
);
echo "sending to google:<br>";
echo json_encode($data);
$ch = curl_init();
$post_values = json_encode( $data );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, 'https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key=xxx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_values);
$data = curl_exec($ch);
if(!curl_errno($ch))
{
echo 'Received raw data' . $data;
}
我检查了我的 google API 密钥并尝试了两种类型:“浏览器应用程序的密钥(带有引用者)”和“服务器应用程序的密钥(带有 IP 锁定)”,但结果相同
有没有办法获得有关我的请求被拒绝的原因的更多信息?错误的位置或错误的钥匙?
这是发送给谷歌的数据:
{"location":{"lat":4.63762250793,"lng":51.148788446},"accuracy":50,"name":"Binnenspeeltuin+Het+Fort%2C+Kessel","types":["amusement_park"]}