Google Maps API密钥HTTP限制导致地理编码API出现403错误 [英] Google maps API key HTTP restriction causes 403 error in geocoding API

查看:140
本文介绍了Google Maps API密钥HTTP限制导致地理编码API出现403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将密钥限制为我的域之后,我在地理编码API的Google Maps API仪表板中收到403错误.当密钥不受限制时,地理编码将起作用.目前,我具有以下可接受的HTTP引荐来源网址:

I receive a 403 error in google maps API dashboard for the geocoding API after limiting the key to my domain. The geocoding works when the key is unrestricted. Currently I have the following as acceptable HTTP referrers:

  • https://website.com/*
  • https://www.website.com/*

这使我的基本javascript映射和自动完成表单可以在HTML页面上使用.但是,地理编码是通过访问website.com/markers的python脚本完成的(没有HTML页面,如果您访问它,则仅显示JSON数据).有没有理由不起作用?我在API信息中心中看到了403错误,但在访问website.com/markers时收到了内部服务器错误消息.不受限制时,仪表板显示响应代码200,我可以看到正确的JSON数据.因此,我认为我的代码不是问题.

This allows my basic javascript map and autocomplete forms to work on HTML pages. However, the geocoding is done through a python script that accesses website.com/markers (has no HTML page, just displays JSON data if you visit it). Is there a reason it will not work? The 403 error is what I see in the API dashboard, but I receive an internal server error message when visiting website.com/markers. When unrestricted, the dashboard shows response code 200 and I can see the correct JSON data. Therefore, I believe my code is not the issue.

我尝试过的事情:

  • 允许" https://website.com/markers "作为引荐来源网址,以及www.版本和http版本.也可以使用没有http或https的版本.
  • 更改为允许网站的IP地址(执行此操作时会发生不允许引荐来源的错误)
  • 仔细检查代码中对API密钥的所有引用.在不受限制的情况下,代码可以在开发和生产中起作用.
  • 再次检查是否已在Google api控制台中启用了所有必需的服务,并且未超过配额.
  • Allowing "https://website.com/markers" as a referrer, as well as www. version of that, and http versions. Also used versions without http or https.
  • Changing to allow IP address of website (referrer not allowed error happens when I do this)
  • Double checking all references to API key in code. Code works in development and in production when unrestricted.
  • Double checked that all needed services are enabled in Google api console and not over quotas.

我已经搜索了这个问题好几个小时了,但是找不到答案,如果我忽略了一些简单的事情,请对我轻松一点.

I have searched for this issue for hours and cannot find an answer, please go easy on me if I have overlooked something simple.

推荐答案

听起来您正在尝试使用旨在与客户端Web api一起使用的URL限制方法.在这种情况下,将在验证中使用网站的公共URL.

It sounds like you're trying to use the method of URL restriction intended for use with client-side web api's. In that case, the public URL of the site is used in the validation.

您要使用IP地址验证,该验证用于服务器端呼叫.

You want to use the IP address validation, intended for server-side calls.

以下内容来自 https://developers.google.com/maps/faq#keysystem :

API密钥:API密钥是您使用 Google API控制台. API密钥通常与标准一起使用 蜜蜂.高级计划客户1通常可以选择使用客户ID 或API密钥.您可以选择使用API​​密钥而不应用 限制(称为通用API密钥")或具有限制的密钥 申请了更高的安全性.任何平台上的API都可以使用通用 API密钥.

API Key: An API key is a unique identifier that you generate using the Google API Console. API keys are generally used with the standard APIs. Premium Plan customers1 typically can choose to use a client ID or an API key. You can choose to use an API key without applying restrictions (called a "generic API key") or a key with restrictions applied for greater security. APIs in any platform may use a generic API key.

您可以选择将限制(例如IP地址)添加到 API密钥.一旦受到限制,密钥将仅在以下平台上起作用: 支持这种类型的限制.四种类型的API密钥限制 可用:

You can optionally add a restriction (for example, IP address) to the API key. Once restricted, a key will only work on platforms that support that type of restriction. Four types of API key restrictions are available:

IP地址(单个服务器)-与Web服务API一起使用.

IP addresses (individual servers) - for use with the web service APIs.

  • HTTP引荐来源网址(网站)-与Web API一起使用.

    HTTP referrers (web sites) - for use with the Web APIs.

  • Android应用程序限制(按程序包名称和指纹)-与Android API一起使用.

    Android app restriction (by package name and fingerprint) - for use with the Android APIs.

  • iOS应用程序限制(通过iOS捆绑包标识符)-供使用 使用iOS API.

    iOS app restriction (by iOS bundle identifier) - for use with the iOS APIs.

  • 这篇关于Google Maps API密钥HTTP限制导致地理编码API出现403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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