【问题标题】:PHP: Google Places API return REQUEST_DENIEDPHP:Google Places API 返回 REQUEST_DENIED
【发布时间】:2013-12-01 17:46:34
【问题描述】:

使用 Google 地点 API 添加地点时,我收到“REQUEST_DENIED”。我已经搜索过之前的帖子,我很确定密钥是正确的,因为它可以用于 Google Places Search。

可能与我的编码有关?这是我的 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;
                }

【问题讨论】:

    标签: php google-places-api


    【解决方案1】:

    根据 Google API 控制台帮助“Android 和 iOS 密钥仅受某些 API 支持,例如 Google Maps Android API 或适用于 iOS 的 Google Maps SDK。” (https://developers.google.com/console/help/)。你可以在这里找到详细信息

    在我的情况下,问题是通过使用“用于 Bowser 应用程序的密钥”而不是使用 android/iOs 密钥来解决的。

    【讨论】:

      猜你喜欢
      • 2012-02-22
      • 1970-01-01
      • 2013-09-12
      • 2012-01-15
      • 2012-05-10
      • 2013-07-15
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多