【问题标题】:Google Places API always return errorGoogle Places API 总是返回错误
【发布时间】:2015-05-05 04:55:35
【问题描述】:

我已在我的 android 应用程序中集成了 Google Places API。 我已经阅读了api文档See Here

我已经为 android 激活了 Google Places Api 并生成了浏览器密钥 当我调用 api 时得到错误响应 -

{"error_message" : "This API project is not authorized to use this API.Please ensure that this API is activated in the APIs Console: Learn more: https://code.google.com/apis/console",
  "html_attributions" : [],
  "results" : [],
  "status" : "REQUEST_DENIED"
}

我也尝试创建 android 密钥并返回 -

{
 "error_message" : "This IP, site or mobile application is not authorized to use this API key.",
 "html_attributions" : [],
 "results" : [],
 "status" : "REQUEST_DENIED"
}

我没有发现我的代码有什么问题。

感谢任何帮助。提前致谢。

检查 API 控制台 -

【问题讨论】:

  • 能给个你用过的网址吗?
  • KISS 使用正确的 API 密钥(浏览器密钥)
  • 也尝试使用浏览器密钥,检查我的问题
  • 经过大量搜索后,通过从控制台激活“Google Places API Web Service”api 找到了解决方案。我不确定这是否正确,因为它是付费 api,我正在使用它在 android 上,它是一个 web api。

标签: android google-places-api


【解决方案1】:

我遇到了同样的问题。就我而言,问题是我试图通过这个 url 使用简单的 HttpUrlconnection 发送请求:

 https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=62.25227243964484%2C59.12338379770518&radius=500&key=my_key

my_key 是 Google Places API for Android 的密钥,但当我切换到 Google Places API Web 服务 时,它可以正常工作。似乎要使用适用于 Android 的 Google Places API 的密钥,您应该遵循本指南https://developers.google.com/places/android/

【讨论】:

    【解决方案2】:

    您似乎正在使用 Places API Web 服务,这需要启用“Google Places API Web 服务”并提供服务器密钥:https://developers.google.com/places/webservice/intro#Authentication

    由于您正在构建一个 Android 应用程序,您可能想尝试一下我们在 3 月刚刚发布的适用于 Android 的 Places API :) 文档位于 https://developers.google.com/places/android/

    我希望这会有所帮助!

    【讨论】:

    • 我试过这个,但我得到了同样的错误。我已经为 Android 启用了 Places API。
    • 同意。需要启用 Google Places API 网络服务。
    【解决方案3】:

    我通过以下先决条件解决了这个问题:

    1) 确保您使用的是以下网址

    https://maps.googleapis.com/maps/api/place/autocomplete/json?input=YOURSEARCHTEXT&key=YOUR_SERVER_API_KEY。 不要使用您的 android/IOS API 密钥。

    2) 确保您已在控制台中启用以下 API。

    Google Places API 网络服务(付费服务)

    【讨论】:

    • 在启用 Google Places API Web 服务(免费服务)之后......它对我有用...... Thnkx @Shoaib
    • @AmitabhaBiswas +1 免费服务也对我有用。我使用 Android 密钥同时启用了 Places Android API 和 Places Web 服务。
    【解决方案4】:

    其实我也遇到过这个问题,但是启用“Google Places API Web Service”对我有用。

    问题是我们正在使用 Google Places 的网络服务来获取位置,而我们忘记在 Google 开发者控制台中启用 Google Places API Web Service

    所以请确保在您使用 Google Place API 时,不要忘记启用 Google Maps Android APIGoogle Places API Web Service

    【讨论】:

      【解决方案5】:

      确保您已启用 Google Places API 网络服务。 因为适用于 Android 的 Google Places API 不适合它。
      希望它会起作用。
      如果不 然后使用简单的 url "https://maps.googleapis.com/maps/api/place/autocomplete/json?key=YOUR_API_KEY&components=country:gr&input=YOUR_INPUT_VALUE" 像 POSTJSON 谢谢。

      【讨论】:

        【解决方案6】:

        在使用 google places api 时,您的 android api 密钥将不起作用,创建一个服务器密钥并在发出请求时在 places url 中使用该服务器。在清单中,您将使用相同的 android api 密钥。这应该可以解决您的问题。

        【讨论】:

          【解决方案7】:

          我尝试了很多次,我找到了解决方案

          如果您要从您的应用发送 URL 以获取地点信息,那么您正在使用 Google Places API 网络服务 不是 Google Places API for Android

          因此,您必须在 API Dashboard 上启用 Google Places API Web Service,它才会起作用。

          【讨论】:

            【解决方案8】:

            使用 Android API 代替浏览器和服务器 API 密钥。遇到了同样的问题,但使用 Android API 密钥解决了。

            【讨论】:

              【解决方案9】:

              启用“Google Maps Android API”后启用“Google Maps Geocoding API”

              【讨论】:

                【解决方案10】:

                确保您启用了“Google Places API Web Service”,并且您必须使用服务器密钥(不是 Android 密钥)

                【讨论】:

                  【解决方案11】:

                  我通过在开发者控制台中启用 Geocoding api 解决了这个问题。

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-10-30
                    • 1970-01-01
                    • 1970-01-01
                    相关资源
                    最近更新 更多