简体   繁体   English

Google附近的地方Android版-需要应用限制

[英]Google Nearby Places Android - Need to apply Restrictions

I wanted to show nearby places in my android app which as per my understanding is only supported by Google Places API and not by Places SDK for Android . 我想在我的android应用中显示附近的地点,据我了解, 该地点仅受Google Places API支持,而不受AndroidPlaces SDK支持 I went ahead with Google Places API option and have added the same in my android app. 我继续使用Google Places API选项,并将其添加到了我的android应用程序中。 I want to restrict API usage to only API calls coming via Android app. 我想将API使用限制为仅通过Android应用程序来的API调用。 However since it goes as a plain GET request via mobile app, i am unable to restrict it with Android App option in my Google API restrictions by providing SHA-1 and namespace of android app. 但是,由于它是通过移动应用程序发出的普通GET请求,因此我无法通过提供SHA-1和Android应用程序的命名空间来使用Google API限制中的Android App选项对其进行限制。 What is the other way out? 还有什么出路?

You are using Places API web service. 您正在使用Places API网络服务。 Typically Google Maps APIs web services are supposed to be called from backend servers and they support only IP address restrictions. 通常,应该从后端服务器调用Google Maps API Web服务,并且它们仅支持IP地址限制。

You can read about restrictions that can be set for different APIs at 您可以在以下位置阅读有关可以为不同API设置的限制的信息:

https://developers.google.com/maps/faq#keysystem https://developers.google.com/maps/faq#keysystem

As you can see Places API web service can use only IP address restriction. 如您所见,Places API Web服务只能使用IP地址限制。 As you are sending requests directly from mobile devices it doesn't make much sense. 当您直接从移动设备发送请求时,这没有多大意义。 Each device has its own IP address and you don't know IP addresses of devices. 每个设备都有自己的IP地址,而您不知道设备的IP地址。 So the only feasible workaround in order to protect API key is creation of the intermediate backend server. 因此,为了保护API密钥,唯一可行的解​​决方法是创建中间后端服务器。

The app should send request to your intermediate server with corresponding authentication, your intermediate backend server should send request to Google with protected API key restricted to IP address of your server and proxy results back to your app. 该应用程序应使用相应的身份验证将请求发送到您的中间服务器,您的中间后端服务器应使用受保护的API密钥(仅限于您服务器的IP地址)将请求发送到Google,并将代理结果返回给您的应用程序。

In this scenario you need two API keys. 在这种情况下,您需要两个API密钥。 One for Google Maps Android SDK with Android app restriction and another one for Places API web service with IP address restriction. 一个用于具有Android应用程序限制的Google Maps Android SDK,另一个用于具有IP地址限制的Places API Web服务。

I hope this helps! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM