【发布时间】:2015-04-04 04:32:39
【问题描述】:
问题是关于 Google Translate API
我设置了一个项目并开启了结算(账户上有一些钱)
我为服务器应用程序创建了一个密钥(也尝试使用浏览器密钥)并添加了我拥有的所有 3 个 IP(家庭和 2 个服务器)
我所看到的:
它可以在 apis-explorer 和浏览器地址栏中工作 (https://www.googleapis.com/language/translate/v2/detect?q=an%20english%20text&key=MY_KEY)
-
如果我试图从 PHP 代码中获取相同的 URL,它会返回 403 错误:
$apiKey = 'MY_KEY';
$url = 'https://www.googleapis.com/language/translate/v2/detect?q=an%20english%20text&key=' 。 $apiKey 。 '';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
curl_close($handle);
print_r(json_decode($response, true));
三个结果:
Array (
[error] => Array (
[errors] => Array (
[0] => Array (
[domain] => usageLimits
[reason] => ipRefererBlocked
[message] => 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 API key configuration if request from this IP or referer should be allowed.
[extendedHelp] => https://console.developers.google.com
))
[code] => 403
[message] => 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 API key configuration if request from this IP or referer should be allowed.
))
我检查了几十次 IP,尝试使用带有允许 URL 的浏览器密钥作为引用。 没有想法。
【问题讨论】:
标签: php google-api google-translate