【问题标题】:Why am I getting "Request Denied" - Google Places API为什么我收到“请求被拒绝” - Google Places API
【发布时间】:2017-04-08 23:02:10
【问题描述】:

我正在尝试使用 Google Places API 添加地点。

API IS 已启用且 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",
 "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" }

帮助:-)

【问题讨论】:

    标签: google-maps google-places-api google-places


    【解决方案1】:

    根据此thread,确保您已在控制台中启用您的 API。

    您正在使用 http(s) 调用 Google API,您的 html 是否也托管在 http(s) 下。如果没有尝试将 google url 更改为 http。

    否则其他一切看起来都还不错,这让我觉得您可能想再次检查您的 api 控制台,转到 SERVICES 并检查您的“Places API”是否已打开。

    您也可以尝试将端口地址更改为 443 以获取 Places API 的响应

    以下是一些可能也有帮助的链接:

    【讨论】:

      【解决方案2】:

      这里的问题是我在 json 上使用了“json_encode”。

      我不需要对其进行编码,这会引发错误。

      故事的士气,不要Json_encode Json。

      【讨论】:

        猜你喜欢
        • 2013-11-29
        • 1970-01-01
        • 1970-01-01
        • 2012-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-30
        相关资源
        最近更新 更多