首页 文章

此IP,站点或移动应用程序无权使用此API密钥

提问于
浏览
72

我在用https://maps.googleapis.com/maps/api/geocode/json?链接服务器密钥和用户IP以查找任何地址的纬度和经度,当我尝试我发现错误为

我有一个来自谷歌的服务器访问密钥,我已将我的服务器的IP地址放在他们的白名单中 .

我试图通过PHP CURL访问的URL是:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true&key=XXXXXXXXXXXX

结果我得到:

Array ([error_message] => This IP, site or mobile application is not authorized to use this API key. [results] => Array ( ) [status] => REQUEST_DENIED)

有什么我需要配置 . 地理编码api也已打开 .

9 回答

  • 1

    I had the same issue and I found this.

    在网址上,它最终需要服务器密钥而不是应用程序的api密钥 .

    所以基本上,你只需在URL的末尾添加服务器密钥,如下所示:

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&sensor=true&key=SERVERKEY

    现在,要获取服务器密钥,只需 follow these steps:

    1) 访问开发者控制台https://code.google.com/apis/console/

    2) 在凭据中的Public API Access下,创建新密钥

    3) 从选项中选择服务器密钥 .

    4) 在字段中输入您的IP地址,如果您有更多的IP地址,则可以添加每一行 . NOTE: 仅在您要将其用于测试目的时输入IP地址 . 否则,将IP地址部分留空 .

    5) 完成后,单击“创建”,将生成新的服务器密钥,然后您可以将该服务器密钥添加到URL中 .

    最后一点是,不是将sensor = true放在URL的中间,而是可以将它添加到最后,如下所示:

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&key=SERVERKEY&sensor=true

    这肯定会解决问题,只记得使用 Places API 的服务器密钥 .

    希望这个答案能够帮助你和其他 Spectator . 祝好运 .. :)

  • 133

    除了分配给您的API密钥之外,Google还会通过查看 REFERRER 或IP地址来验证传入请求的来源 . 要在curl中运行示例,请在Google APIs console中创建一个新的 Server Key . 创建它时,您必须提供服务器的IP地址 . 在这种情况下,它将是你的local IP address . 创建 Server Key 并将您的IP地址列入白名单后,您应该能够在curl中使用新的API密钥 .

    我的猜测是你可能创建了一个 Browser Key 的API密钥,它不需要你将你的IP地址列入白名单,而是使用 REFERRER HTTP头标记进行验证 . curl默认情况下不会发送此标记,因此Google未能验证您的请求 .

  • 5

    Google Places API目前不支持从Google API控制台生成的Android或iOS密钥 . 目前仅支持服务器和浏览器键 .

  • 2
    • 选择键

    • API限制选项卡

    • 选择API密钥

    • 保存

    • 选择应用程序限制 - >无

    • 保存

    enter image description here

    enter image description here

    enter image description here

    enter image description here

  • -1

    您创建一个没有引用的键不要输入引用地址

  • 5

    Google Place API要求在进行API调用时包含referer HTTP标头 .

    包括HTTP标头“Referer:yourdomain.com”,这应该可以解决响应问题 .

  • -1

    此外,应为给定项目启用相应的API

    https://console.developers.google.com/apis/library?project=projectnamehere

  • 13

    我遇到了问题,因为我没有在Google控制台中启用APL密钥 .

  • 1
    url = https://maps.googleapis.com/maps/api/directions/json?origin=19.0176147,72.8561644&destination=28.65381,77.22897&mode=driving&key=AIzaSyATaUNPUjc5rs0lVp2Z_spnJle-AvhKLHY
    

    仅在AppDelegate中添加

    GMSServices.provideAPIKey("AIzaSyATaUNPUjc5rs0lVp2Z_spnJle-AvhKLHY")
    

    并删除此网址中的密钥 .

    现在网址是

    https://maps.googleapis.com/maps/api/directions/json?origin=19.0176147,72.8561644&destination=28.65381,77.22897&mode=driving
    

相关问题