A API de contatos do Google responde com o erro "countryBlock"
Eu tenho um aplicativo que importa contatos dos Contatos do Google. O aplicativo funcionou bem até hoje de manhã, quando alteramos o 'proprietário' da API. Foi criado em minha conta pessoal para fins de desenvolvimento.
Depois de configurar tudo, o Google começou a responder com isso:
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
)
)
Esta é a linha que gera o erro e a declaração de funções (elas estão em arquivos diferentes):
$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;
}
Eu tentei forçar um IP diferente usando:curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
e eu comentei a linha do agente do usuário. No entanto, sem sorte.
Quando eu o executo no meu host local, ele funciona bem, sem erros. Estou na África do Sul e o servidor em que esse erro é gerado está na Alemanha.
Tentei pesquisar no Google as políticas de país do Google, mas não consegui.
Alguém pode explicar por que isso está acontecendo e como posso contorná-lo?