As soon as I restrict my Google API key it no longer works

◇◆丶佛笑我妖孽 提交于 2019-12-02 12:19:46

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41310052/as-soon-as-i-restrict-my-google-api-key-it-no-longer-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!