只要我限制我的Google API密钥,它就不再有效 [英] As soon as I restrict my Google API key it no longer works

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

问题描述

我有一个我正在使用的Google API密钥,并且一直适用于Google地图。我现在正在尝试将Google Maps Distance Matrix API与我的Android应用程序一起使用,如果我不将自己的密钥限制在Android应用程序中,则只能使用它。只要我将密钥限制在我的包和SHA1指纹中,它就不再起作用。我再次从AndroidManifest中检查了包名,并确保我使用了正确的密钥库&别名组合,但它似乎并不重要。请注意,Android应用限制仅适用于Google地图Android API v2,并且仅限于Google Maps Android API v2。请注意,Android应用限制仅适用于Google Maps Android API v2,适用于Android的Google地图位置。 Web服务(例如距离矩阵API)不适用于此限制。



可用于Web服务的API密钥的限制是IP限制。



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


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?

解决方案

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.

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

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天全站免登陆