【问题标题】:Google Places API Web Services API Key InvalidGoogle Places API 网络服务 API 密钥无效
【发布时间】:2015-12-17 17:16:49
【问题描述】:

我刚刚注册了Google Places API。他们发给我一个server key,我在我的代码中使用它。

这是我的代码:

    function getLatLon($address)
    {
      $curl=curl_init();
      curl_setopt($curl,CURLOPT_URL,'https://maps.googleapis.com/maps/api/geocode/json?address='.rawurlencode($address));
      curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
      $json=curl_exec($curl);
      curl_close($curl);
      $json=json_decode($json);
      $details=[
         'lat'=>$json->results[0]->geometry->location->lat,
         'lng'=>$json->results[0]->geometry->location->lng
      ];
      return $details;
    }


    function getDetails($address)
    {
      $apikey='googlesuppliedapikey';
      $locdetails=getLatLon($address);
      $latitude=$locdetails['lat'];
      $longitude=$locdetails['lng'];
      $curl=curl_init();
      curl_setopt($curl,CURLOPT_URL,'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$latitude,$longitude&key=$apikey');
      curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
      $json=curl_exec($curl);
      curl_close($curl);
      $json=json_decode($json);
      print_r($json);
    }


    $address='3342 Shawnee Avenue Avenue West Palm Beach, FL 33409';
    getDetails($address);

纬度和经度功能工作正常。我的问题在getDetails function 内。

我目前的反应如下

stdClass Object
(
   [error_message] => The provided API key is invalid.
   [html_attributions] => Array
    (
    )

   [results] => Array
    (
    )

   [status] => REQUEST_DENIED
)

不太清楚是什么问题。我真的只是在 5 分钟前创建了这个 API 密钥。 我也尝试了昨天创建的先前密钥,它提供了相同的答案

无论如何感谢您的帮助。

【问题讨论】:

    标签: php google-maps-api-3


    【解决方案1】:

    您的请求网址不正确。

    来自the documentation

    地点详情请求

    地点详情请求是以下形式的 HTTP URL:

    https://maps.googleapis.com/maps/api/place/details/output?parameters 其中输出可以是以下任一值:

    json(推荐)表示以 JavaScript Object Notation (JSON) 输出 xml 表示输出为 XML 启动搜索请求需要某些参数。与 URL 中的标准一样,所有参数都使用与 (&) 字符分隔。下面是参数列表及其可能的值。

    key(必需)- 您的应用程序的 API 密钥。此密钥标识您的应用程序以进行配额管理,以便您的应用程序可以立即使用从您的应用程序添加的位置。访问 Google Developers Console 以创建 API 项目并获取您的密钥。 placeid 或参考(您必须提供其中之一,但不能同时提供两者): placeid — 唯一标识地点的文本标识符,从地点搜索返回。有关地点 ID 的更多信息,请参阅地点 ID 概述。 reference — 唯一标识地点的文本标识符,从地点搜索返回。注意:现在不推荐使用该引用,取而代之的是 placeid。请参阅此页面上的弃用通知。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-19
      • 2013-09-09
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多