Google maps 为什么我会得到;请求被拒绝";-googleplacesapi
我正在尝试使用GooglePlacesAPI添加一个位置 API已启用且API密钥有效。这是我的密码:Google maps 为什么我会得到;请求被拒绝";-googleplacesapi,google-maps,google-places-api,google-places,Google Maps,Google Places Api,Google Places,我正在尝试使用GooglePlacesAPI添加一个位置 API已启用且API密钥有效。这是我的密码: $url = "https://maps.googleapis.com/maps/api/place/add/json?key=MYKEY"; $content = json_encode('{ "location": { "lat": 55.9868532, "lng": -4.5780577 }, "accuracy": 50, "name": "Home Made Pizza", "t
$url = "https://maps.googleapis.com/maps/api/place/add/json?key=MYKEY";
$content = json_encode('{
"location": {
"lat": 55.9868532,
"lng": -4.5780577
},
"accuracy": 50,
"name": "Home Made Pizza",
"types": ["other"],
"website": "http://example.com",
"language": "en-AU"
}');
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("response $json_response");
};
curl_close($curl);
$response = json_decode($json_response);
我得到的回应是
response { "status" : "REQUEST_DENIED" }
帮助:-)基于此,请确保已在控制台中启用API
您正在使用http(s)调用Google API,您的html是否也托管在http(s)下。如果没有,请尝试将google url更改为http
否则,其他一切看起来都很正常,所以我认为您可能想再次检查您的api控制台,转到服务并检查您的“PlacesAPI”是否已打开
您还可以尝试将端口地址更改为443,以从PlacesAPI获取响应
以下是一些可能也有帮助的链接:
- 这里的问题是我在json上使用了“json\u encode”
我不需要对它进行编码,这是一个错误
故事的主题是,不要对Json编码