我有一个从Google通讯录导入联系人的应用。该应用程序工作正常,直到今天早上我们更改了API'所有者'。它是在我的个人帐户下设置的,用于开发目的。
设置完所有内容后,Google开始回复:
Array
(
[error] => Array
(
[errors] => Array
(
[0] => Array
(
[domain] => global
[reason] => countryBlocked
[message] => This service is not available from your country
)
)
[code] => 403
[message] => This service is not available from your country
)
)
这是生成错误的行和函数声明(它们在不同的文件中):
$xmlresponse = curl_file_get_contents($url);
function curl_file_get_contents($url)
{
$curl = curl_init();
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
curl_setopt($curl, CURLOPT_URL, $url); //The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); //The number of seconds to wait while trying to connect.
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //To stop cURL from verifying the peer's certificate.
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
我尝试使用curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
强制使用其他IP,并且我已经注释掉了用户代理行。但是,没有运气。
当我从本地主机运行它时,它运行正常,没有错误。我在南非和服务器上生成此错误,是在德国。
我已经尝试使用Google搜索谷歌的国家/地区政策,但却做空了。
任何人都可以解释为什么会发生这种情况以及如何绕过它吗?
答案 0 :(得分:1)
此错误表示Google认为您的IP地址属于country with restricted access。然而德国不是这些国家之一,所以这可能是一个错误。请填写以下表格以更正:https://support.google.com/websearch/contact/ip
答案 1 :(得分:0)
查看这个帖子,这是类似的。它说这个问题是由谷歌API中央核心与http:requests(而不是https :)联系
引起的Intermittent 403 "This service is not available from your country" Error for execution API