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

查看:38
本文介绍了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)执行.即使在请求标头中手动设置引用者,它对我也不起作用.您可以在此页面上找到其他网络服务 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/

重要提示:如果您使用具有引用限制的 API 密钥的任何 Web 服务 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 常见问题解答中有关将密钥类型切换为服务器受限密钥的部分:https://developers.google.com/maps/faq#switch-key-type

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天全站免登陆