Google Contacts API 响应“countryBlock"错误 [英] Google Contacts API responds with "countryBlock" error

查看:27
本文介绍了Google Contacts API 响应“countryBlock"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 Google 通讯录导入联系人的应用.该应用程序运行良好,直到今天早上我们更改了 API所有者".它是在我的个人帐户下设置的,用于开发目的.

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.

设置完所有内容后,Google 开始响应:

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

我尝试使用以下方法强制使用不同的 IP:curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip")); 并且我评论了退出用户代理行.然而,没有运气.

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.

我曾尝试在谷歌上搜索 Google 的国家/地区政策,但没有找到.

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?

推荐答案

此错误表明 Google 认为您的 IP 地址属于 访问受限的国家.然而,德国不是这些国家之一,所以这可能是一个错误.请填写以下表格以更正此问题:https://support.google.com/websearch/联系人/ip

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

这篇关于Google Contacts API 响应“countryBlock"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆