API密钥与该API一起使用时,浏览器API密钥不能具有引用限制 [英] API key Browser API keys cannot have referer restrictions when used with this API

查看:256
本文介绍了API密钥与该API一起使用时,浏览器API密钥不能具有引用限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对地址解析进行编程.我创建了API密钥,但是当我将其添加到我的网站代码中时,我什么也没得到,但是当我不使用API​​时,一切都很好.当我发送时:

I'm trying to program geocoding. I created API key, but when I add it into my website code I don't get anything, however when I don't use API everything works well. When I'm sending:

https://maps.googleapis.com/maps/api/geocode/json?address=".$adres."&key=KLUCZ_XXX

我得到答复:

Browser API keys cannot have referer restrictions when used with this API.

如果我使用:

https://maps.googleapis.com/maps/api/geocode/json?address=".$adres" 

结果是正确的,但是每天的查询数量是有限的.

The result is correct but the number of queries is limited per day.

关键约束:引荐HTTP(Web)-设置为从其召唤查询的域.界面Google Maps Geocoding API已打开.

Key constraint: referrals HTTP (Web) - set to the domain from which conjure inquiry. Interface Google Maps Geocoding API is turned on.

是否还必须在其他地方激活API密钥?

Does the API key has to be activated also somewhere else to work?

推荐答案

听起来您可能正在使用API​​调用服务器端.我今天早些时候遇到了这个问题.由于您已在API密钥上设置了引荐来源网址限制,因此它将仅限于使用Web服务API(包括地址编码API)在浏览器上执行.即使在请求标头中手动设置引荐来源网址,它也对我不起作用.您可以在此页面上找到其他Web服务API: https://developers.google.com/地图/网络服务/

It sounds like you may be making the API call server side. I ran into this issue earlier today. Since you've placed a referrer restriction on your API key, it will be limited to executing on the browser with the web service APIs, including the Geocoding API. It didn't work for me even when manually setting the referrer in the request headers. You can find the other web service APIs on this page: https://developers.google.com/maps/web-services/

重要:如果您使用的任何Web服务API的API密钥都有引用限制,则您的请求将失败,并显示错误消息:与该API一起使用时,API密钥不能具有引用限制."您应该切换到使用服务器限制.

Important: If you are using any of the web service APIs with an API key that has referer restictions, your requests will fail with the error message: "API keys cannot have referer restrictions when used with this API." You should switch to using a server restriction.

您将要创建一个单独的密钥以使用服务器端.您可以使用IP地址(而不是浏览器引荐来源网址)限制访问,从而将限制从浏览器限制更改为服务器限制.

You'll want to create a separate key to use server-side. You can change your restriction from a browser restriction to a server restriction by using IP addresses to restrict access, instead of browser referrers.

有关将密钥类型切换为服务器受限密钥的信息,请参阅Maps API常见问题解答中的以下部分:

See this section in the Maps APIs FAQ on switching key type to a server restricted key: https://developers.google.com/maps/faq#switch-key-type

或者,您可以继续使用浏览器键和地理编码客户端(JavaScript),然后通过ajax将结果返回到后端.

Alternatively, you can continue using a browser key and geocode client-side (JavaScript), then return the result to the backend via ajax.

这篇关于API密钥与该API一起使用时,浏览器API密钥不能具有引用限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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