dousu5608 2014-10-21 11:42
浏览 43
已采纳

Google通讯录API以“countryBlock”错误响应

I have an app that imports contacts from Google Contacts. The app worked fine, until this morning when we changed the API 'owner'. It was set up under my personal account for development purposes.

After setting up everything, Google started responding with this:

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
        )
)

This is the line that generates the error, and the functions declaration (they are in different files):

$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;
}

I've tried forcing a different IP using: curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip")); and I've commented out the user agent line. However, no luck.

When I run it from my localhost, it works fine with no errors. I am in South Africa and the server this error is generated on, is in Germany.

I've tried googling for Google's country policies but came up short.

Can anyone explain why this is happening and how I can bypass it?

  • 写回答

2条回答 默认 最新

  • douxian5963 2014-10-21 14:36
    关注

    This error indicates that Google believes your IP address belongs to a country with restricted access. Germany is not one of those countries however, so this is likely an error. Please fill out the following form to have this corrected: https://support.google.com/websearch/contact/ip

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上