简体   繁体   English

显然 flutter_google_places 需要代理服务器?

[英]Apparently flutter_google_places requires a proxy server?

Okay, I must be an unbearable noob to iOS programming, using API's or using XCode in general, because apparently changing the API-Keys in my program to any sort of Restricted API Key breaks my program.好吧,我一定是一个无法忍受的 iOS 编程新手,使用 API 或一般使用 XCode,因为显然将我的程序中的 API 密钥更改为任何类型的受限 API 密钥会破坏我的程序。

I'm building my app using flutter (Writing most of the code in VSCode).我正在使用 flutter 构建我的应用程序(在 VSCode 中编写大部分代码)。

In my pubspec.yaml I have the following dependencies (Just incase it's relevant).在我的 pubspec.yaml 中,我有以下依赖项(以防万一它是相关的)。

dependencies:
  flutter:
    sdk: flutter
  firebase_auth: ^0.15.4
  google_sign_in: ^4.1.4
  firebase_core: 0.4.4
  google_maps_flutter: ^0.5.24+1
  geolocator: ^5.3.0
  flutter_google_places: ^0.2.4
  geocoder: ^0.2.1
  http: ^0.12.0+4
  intl: ^0.16.1

If I use the unrestricted Web API Key for my program, as the googleMapKay, I have no problems, and the following code works perfectly.如果我为我的程序使用不受限制的 Web API 密钥,作为 googleMapKay,我没有问题,并且以下代码完美运行。

  Future<void> _originAutocomplete() async {
    Prediction p = await PlacesAutocomplete.show(
        context: context,
        apiKey: googleMapKey,
        mode: Mode.overlay, 
        language: "en",
        location: new Location(last_known_position.latitude, last_known_position.longitude),
        radius: 100000,
        components: []);
        if (p == null) {
          print('p is null');
        }
    originSelected(p);
  }

If however I use the ios-app Restricted API-Key for the same line, p is suddenly null.但是,如果我对同一行使用 ios-app Restricted API-Key,则 p 突然为空。 Now I am using firebase, and I've included the GoogleServices.plist in the program correctly.现在我正在使用 firebase,并且我已经在程序中正确地包含了 GoogleServices.plist。 I've updated the API-Key in my AppDelegate.swift in XCode as well, and also updated the API-Key in the program itself.我也在 XCode 的 AppDelegate.swift 中更新了 API-Key,并且还更新了程序本身中的 API-Key。

I've been testing this on a vairety of devices, iphone se, 5s, 8+, and on simulators for ipad pro 12.9" (third generation), and iphone 11 pro max. In all cases, I have the same error, AND it's fixed when using the unrestricted web API's, which I cannot use in the final release build of the product.我一直在各种设备、iphone se、5s、8+ 以及 ipad pro 12.9"(第三代)和 iphone 11 pro max 的模拟器上对此进行测试。在所有情况下,我都有相同的错误,并且它在使用不受限制的 Web API 时得到修复,我无法在产品的最终发布版本中使用它。

I did also verify that the Restricted API-Key is set to only restrict via iOS apps, and that the bundle-identifier of the program is correctly set inside the google API-Key restrictions.我还验证了 Restricted API-Key 是否设置为仅通过 iOS 应用程序进行限制,并且程序的 bundle-identifier 是否在 google API-Key 限制中正确设置。 (And that there is only application resrictions, no api-restrictions). (而且只有应用程序限制,没有 api 限制)。 So I don't THINK that is the problem, but if you can show me a way to test, then I'd appreciate!所以我不认为这是问题所在,但是如果您能告诉我一种测试方法,那么我将不胜感激! After a little testing I found the copy of the key inside the AppDelegate file doesn't seem to matter, so that one can be restricted without an issue.经过一些测试后,我发现 AppDelegate 文件中的密钥副本似乎无关紧要,因此可以毫无问题地对其进行限制。

After looking into the documentation for flutter_google_places, apparently this has an innate dependancy for google_maps_webservices which requires a web-api to function.在查看了 flutter_google_places 的文档后,显然这对 google_maps_webservices 有先天的依赖,它需要一个 web-api 才能运行。 (If I understand correctly this means an unrestricted key?). (如果我理解正确,这意味着一个不受限制的密钥?)。 This does state that the "correct" industry best-practice would be to use a proxy server?这确实表明“正确”的行业最佳实践是使用代理服务器?

I'm not 100% familiar with this process, or how to do it, or if there's any simple or easy methods to get this working, so any assistance you can provide would be MUCH appreciated!我不是 100% 熟悉这个过程,或者如何做,或者是否有任何简单或容易的方法来让这个工作,所以你能提供的任何帮助将不胜感激!

Google Maps Platform APIs needs to have API key in the request to work properly. Google Maps Platform API 需要在请求中包含 API 密钥才能正常工作。 API keys are recommended to have restrictions set on them to secure and protect your keys.建议对 API 密钥设置限制以保护您的密钥。 Please note that there are different type of restrictions that you can use for your API key and these restrictions should match the appropriate services that are using it, or else, it will throw an error.请注意,您可以对 API 密钥使用不同类型的限制,这些限制应与使用它的相应服务相匹配,否则会引发错误。

I can see that you are using the Google places autocomplete widgets for flutter and this seems to use the Places webservice API.我可以看到您正在使用 Google 地点自动完成小部件进行颤振,这似乎使用了 Places webservice API。 Please know that Places Webservice API is not compatible with iOS restrictions since the APIs/SDKs that can only use this restriction is Places SDK for iOS and Maps SDK for iOS .请注意, Places Webservice APIiOS 限制不兼容,因为只能使用此限制的 API/SDK 是Places SDK for iOSMaps SDK for iOS This might be the reason why you are having the issue when using an iOS restricted API key.这可能是您在使用 iOS 受限 API 密钥时遇到问题的原因。 You might consider just using an API restriction and restrict your key with the Google Maps Platform API your flutter app is using.您可能会考虑仅使用 API 限制,并使用您的 Flutter 应用程序正在使用的 Google Maps Platform API 来限制您的密钥。

Also, on mobile apps that uses Web Service APIs, you can consider the following technics to safeguard yur API keys: Use a proxy server, Obfuscate or encrypt the API key or signing secret and Use CA pinning or certificate pinning to verify the server resources are valid.此外,在使用 Web 服务 API 的移动应用程序上,您可以考虑使用以下技术来保护您的 API 密钥:使用代理服务器、混淆或加密 API 密钥或签名密钥以及使用 CA 固定或证书固定来验证服务器资源是有效的。 These are discuss in this link .这些是在这个链接中讨论的。

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

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