php – Google Contacts API以“countryBlock”错误响应

我有一个从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;
}

我尝试使用以下方法强制使用不同的IP:curl_setopt($ch,CURLOPT_HTTPHEADER,array(“REMOTE_ADDR:$ip”,“HTTP_X_FORWARDED_FOR:$ip”));我已经注释掉了用户代理行.但是,没有运气.

当我从我的localhost运行它时,它没有错误正常工作.我在南非和服务器上生成此错误,是在德国.

我已经尝试使用Google搜索Google的国家/地区政策,但却做空了.

任何人都可以解释为什么会发生这种情况以及如何绕过它?

解决方法:

此错误表示Google认为您的IP地址属于country with restricted access.德国不是其中之一,因此这可能是错误的.请填写以下表格以更正:https://support.google.com/websearch/contact/ip

上一篇:用于在php中检测用户contry的包?


下一篇:BOSS 直聘整站爬取思路总结