一旦我限制了我的 Google API 密钥,它就不再起作用 [英] As soon as I restrict my Google API key it no longer works

查看:27
本文介绍了一旦我限制了我的 Google API 密钥,它就不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用的 Google API 密钥,并且在 Google 地图上运行良好.我现在正在尝试将 Google Maps Distance Matrix API 与我的 Android 应用程序一起使用,如果我不将密钥限制为我的 Android 应用程序,我只能让它工作.一旦我将密钥限制为我的包和 SHA1 指纹,它就不再起作用.我仔细检查了 AndroidManifest 中的包名称,并确保我使用的是正确的密钥库 &别名组合,但似乎无关紧要.还有什么我可以检查的吗?

I have a Google API key that I'm using and has been working fine for Google maps. I am now trying to use the Google Maps Distance Matrix API with my Android app and I can only get it to work if I don't restrict my key to my Android app. As soon as I restrict the key to my package and SHA1 fingerprint it no longer works. I double checked the package name from the AndroidManifest and I made sure I'm using the right keystore & alias combination but it doesn't seem to matter. Is there anything else I can check for?

推荐答案

请注意,Android 应用程序限制仅对 Google Maps Android API v2 和 Google Maps Places for Android 有效.网络服务(例如距离矩阵 API)不适用于此限制.

Please note that Android app restriction is valid only for Google Maps Android API v2 and Google Maps Places for Android. Web services (e.g. Distance Matrix API) will not work with this restriction.

适用于 Web 服务的 API 密钥的限制是 IP 限制.

The restrictions that will work with an API keys for web services are IP restrictions.

假设 Web 服务请求在您的后端服务器上执行.如果您需要限制 API 密钥,解决方法是创建一个中间服务器.您的 Android 应用程序应向中间服务器发送请求,中间服务器应向 Google 发送请求并将响应传递回您的应用程序.在这种情况下,您可以通过中间服务器的 IP 地址限制 API 密钥.

It is supposed that web services requests are executed on your backend servers. If you need to restrict an API key, the workaround is to create an intermediate server. Your Android application should send requests to the intermediate server, intermediate server should send requests to Google and pass responses back to your app. In this case you can restrict an API key by IP address of your intermediate server.

这篇关于一旦我限制了我的 Google API 密钥,它就不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆