我是 Android 新手,正在从事谷歌地图项目。为此,我使用 this库绘制两点之间的路线。
当对 google map api key 没有限制时,这可以正常工作。但是当限制应用于我的应用程序的包名称和 sha1 key 时,它不会显示路由。
它抛出一个异常说:
This IP, site or mobile application is not authorized to use this API key. Request received from IP address XX.XX.XXX.XXX, with empty referrer
有什么方法可以通过受限的 api key 使用这个库吗?我如何向该库添加引荐来源网址?
最佳答案
看起来这个库使用了 Directions API web service ,因此您不能使用受 Android 限制的 API key 。如果这样做,您会收到报告的 request_denied 错误。这是因为 Web 服务是服务器端的,API key 只能受 IP 地址限制。
话虽如此,您是从 Android 应用调用 API。 Google's documentation状态:
IP restrictions might be impractical, such as in mobile applications and cloud environments that rely on dynamic IP addresses. When using Maps Web Service APIs in these scenarios, secure your apps using one or more of the following techniques:
pinning, proxy server, obfuscation
因此,设置代理服务器可能是正确保护 API key 的最佳方式。
希望这能澄清您的问题。
关于android - 如何使用具有受限 API key 的 Google-Directions-Android 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196465/