谷歌地图API,提供的API密钥无效 [英] google maps api, The provided API key is invalid

查看:461
本文介绍了谷歌地图API,提供的API密钥无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次发布关于堆栈溢出的问题,真的希望你们能够提供帮助。



我试图在第一时间使用google maps地理编码api时间和无法让它工作。



我使用的网址格式为:



https:// maps.googleapis.com/maps/api/geocode/json?address=LS2+9AQ&sensor=false&key=[MY_API_KEY]



在这种情况下,我正在寻找使用chrome浏览器打开英国邮政编码:LS2 9AQ。



当我不使用我的api密钥时,url可以正常工作,但是没有使用我的api密钥的限制关键是我的需求太低。



我还没有在生产站点使用它,现在它是从我的本地开发者chrome运行的。



我得到的实际回应是:

  [error_message] =>提供的API密钥无效。 
[results] =>数组



[status] => REQUEST_DENIED

当我删除api键时,它会起作用并返回以下内容:

  {
results:[
{
address_components:[
{
long_name:LS2 9AQ,
short_name:LS2 9AQ,
types:[postal_code]
},
{
long_name:Woodhouse,
short_name:Woodhouse,
types:[sublocality,political]
},
{
long_name:Leeds,
short_name:Leeds,
types:[locality,political]
},
{
long_name:West Yorkshire,
short_name:West York,
types:[administrative_area_level_2,political]
},
{
long_name:United Kingdom,
short_name:GB,
types:[country,political]
},
{
long_name:Leeds,
short_name:Leeds,
types:[postal_town]
}
],
formatted_address:Woodhouse,Leeds,West Yorkshire LS2 9AQ,UK,
geometry:{
bounds:{
northeast:{
lat:53.8090296,
lng:-1.5509549
},
southwest:{
lat:53.8083045,
lng:-1.5519655
}
},
location:{
lat:53.808447,
lng:-1.5517752
} ,
location_type:APPROXIMATE,
viewport:{
northeast:{
lat:53.81001603029149,
lng:-1.550111219708498
},
southwest:{
lat:53.80731806970849,
lng:-1.552809180291502
}
}
},
types:[postal_code]

$ b $ status






$ b

我试图用当前在我的作品网站上使用的一个替换网址,并且我得到了相同的回复,我尝试了两个不同的密钥,我生成了自己,一个是上周创建的,另一个是在一个小时前创建的。我已经按照以下方式设置了钥匙:


  • 支付已启用,并且信用卡已附加到项目中(我被告知此需要通过验证身份来增加对api的限制)
  • 在关键引用链接上的
  • 设置为dev.test.com/*(这是我在本地dev上使用的url为了这)。在另一个键上没有指定引用者。

  • 键是浏览器应用程序键



我肯定正确地输入了密钥,我和另一位开发人员已经多次检查过这个密码,有没有人有任何想法可能会出错?



感谢任何人这有助于。



更新
我发现导致进程在10次迭代后停止工作的问题。谷歌地理编码api有每秒10次调用的限制,我正在考虑这一点,现在我每10次迭代就会在1秒内添加一次延迟,现在理论上可以达到每日限制。



然而,我仍然需要比默认免费限制更多的电话,如我在下面的评论中所述,我相信我可以使用api键来增加基于我拥有经过验证的帐户的免费限制。我正在使用这个业务,但它没有足够的数量值得为此付费。任何人都可以帮我解决这个问题吗?

解决方案

好吧,看起来我想要做的事情是不可能的,一个商业账户。没有办法将apikey应用于Google地理编码api。



我误解了一些有关Google Maps API的文档,其中提到了提高每日查询的允许限制。



这似乎不适用于地理编码api。


This is my first time posting a question on stack overflow, really hoping you guys can help.

I am trying to use the google maps geocodeing api for the first time and cannot get it to work.

The url format I am using is:

https://maps.googleapis.com/maps/api/geocode/json?address=LS2+9AQ&sensor=false&key=[MY_API_KEY]

In this case I am looking up the uk postcode: LS2 9AQ from a chrome browser.

The url does work when I don't use my api key but the limit on the number of allowed calls without the key is too low for my needs.

I am not yet using this in a production site, for now it is running from my local dev in chrome.

The actual response I get is:

[error_message] => The provided API key is invalid.
[results] => Array
    (
    )

    [status] => REQUEST_DENIED

When I remove the api key it works and returns the following:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "LS2 9AQ",
               "short_name" : "LS2 9AQ",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Woodhouse",
               "short_name" : "Woodhouse",
               "types" : [ "sublocality", "political" ]
            },
            {
               "long_name" : "Leeds",
               "short_name" : "Leeds",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "West Yorkshire",
               "short_name" : "West York",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "United Kingdom",
               "short_name" : "GB",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "Leeds",
               "short_name" : "Leeds",
               "types" : [ "postal_town" ]
            }
         ],
         "formatted_address" : "Woodhouse, Leeds, West Yorkshire LS2 9AQ, UK",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 53.8090296,
                  "lng" : -1.5509549
               },
               "southwest" : {
                  "lat" : 53.8083045,
                  "lng" : -1.5519655
               }
            },
            "location" : {
               "lat" : 53.808447,
               "lng" : -1.5517752
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 53.81001603029149,
                  "lng" : -1.550111219708498
               },
               "southwest" : {
                  "lat" : 53.80731806970849,
                  "lng" : -1.552809180291502
               }
            }
         },
         "types" : [ "postal_code" ]
      }
   ],
   "status" : "OK"
}

I have tried replacing the url with one that is currently in use on my works website and I got the same response, I have tried two different keys that I generated myself, one created last week and the other created an hour ago. I have set up the keys in the following way:

  • payment is enabled and a credit card is attached to the project (I was told this was needed to increase limit on api's by validating identity)
  • on one key referrer is set to "dev.test.com/*" (this is the url I am using on my local dev for this). On the other key no referrer is specified.
  • the key is a browser apps key

I am definitely entering the key properly, both me and another developer have checked this multiple times, does anyone have any ideas on what could be wrong?

Thanks in advance to anyone that helps.

UPDATE I have found the problem that was causing the process to stop working after 10 iterations. The google geocoding api has a limit of 10 calls per second in place and I was going over this, I have now added in a 1 second delay every 10 iterations and I can now in theory reach the daily limit.

However I still need more calls than the default free limit, as described in my comments below I believe I can use an api key to increase the free limit based on me having a verified account. I am using this for business but it is not high enough volume to be worth paying for it. Can anyone help clear this up for me?

解决方案

Ok, It looks like what I was trying to do is impossible without paying for a business account. There is no way to apply an apikey to the google geocoding api.

I had misunderstood some documentation regarding the google maps api which referred to raising the allowed limit on daily queries.

This does not seem to apply to the geocoding api.

这篇关于谷歌地图API,提供的API密钥无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆