【问题标题】:Allow-all Referer Rule for Google Translate API (v2)?允许谷歌翻译 API (v2) 的所有引用规则?
【发布时间】:2015-01-27 18:34:08
【问题描述】:

我正在尝试构建一个 SMS(文本消息)应用程序,它使用 Google Translate API 来翻译发送给它的文本。我已经设置了 App Engine 和选择公共 API 密钥访问的整个 8000 步过程,而不是选择 oauth,在意识到如果不给 Google 信用卡号码就不会让我手动设置配额限制,然后设置计费,最后进入“编辑允许的引用者”,我将其设置为:

*

...在调试时,我打算将其更改为代码所在位置的实际 URL。

使用星号不起作用。我必须使用 Google Translate API v2 Public API referrer 规则的语法来允许来自网络空间中任何地方的连接,比如 Apigee?目前这个调用(用 MY_KEY_HERE 代替了实际的键):

https://www.googleapis.com/language/translate/v2?key=MY_KEY_HERE&q=hello%20world&source=en&target=de

返回:

{
  "error":  {
    "errors":  [
       {
        "domain": "usageLimits",
        "reason": "accessNotConfigured",
        "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
        "extendedHelp": "https://console.developers.google.com"
      }
    ],
    "code": 403,
    "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
  }
}

【问题讨论】:

  • 我还尝试过 *.apigee.com/* 仅用于 apigee,*.herokuapp.com/* 用于我为测试而启动的 Heroku 实例。都不工作。这些规则的语法是什么没有参考。
  • 旁注:根据我设置的 API 配额,我没有接近我的速率限制:TOTAL QUOTA 2,000,000 characters/day REMAINING 2,000,000 characters/day 100% of total

标签: api google-api google-translate gcloud


【解决方案1】:

要回答您的问题,您可以将“接受来自这些 HTTP REFERERS(网站)的请求”字段留空。然后密钥将具有“允许任何引用者”(确认工作)。

允许任何推荐人都不是一个好主意,因为您的密钥可能会被泄露。从您的用例来看,您可以拥有一个Endpoint,它将接受文本进行翻译并将其返回翻译。实际的 Translate API 调用将在具有 OAuth2 的端点上完成以访问 API。

【讨论】:

  • 谢谢!我计划更改为限制到生产域,但现在将其保持打开状态,以便我可以调试正在使用的库进行的 API 调用。
猜你喜欢
  • 2019-09-23
  • 1970-01-01
  • 1970-01-01
  • 2013-03-17
  • 2018-12-25
  • 1970-01-01
  • 2020-06-03
  • 2012-01-26
  • 2012-08-06
相关资源
最近更新 更多