2

I have used google api for Analytics service. First 3 days from this implementation, it worked fine, but from 30th Apr 2015. suddenly it got trouble with the following error. I have executed this php program through a web page access by using Apache cron. When I access to the page, it return 500 error and

PHP Error log;

PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'Couldn't resolve host 'accounts.google.com'' in /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/IO/Curl.php:115\nStack trace:\n#0 /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/IO/Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request))\n#1 /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/Auth/OAuth2.php(336): Google_IO_Abstract->makeRequest(Object(Google_Http_Request))\n#2 /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/Auth/OAuth2.php(308): Google_Auth_OAuth2->refreshTokenRequest(Array)\n#3 /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/get-pageview.php(52): Google_Auth_OAuth2->refreshTokenWithAssertion(Object(Google_Auth_AssertionCredentials))\n#4 /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/get-pageview.ph in /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/IO/Curl.php on line 115

My code to connect google api;

require_once dirname(__FILE__) . '/src/Google/autoload.php';    
$client_email = 'xxx@developer.gserviceaccount.com';    
$view_id = "xxx";    
$private_key = @file_get_contents(dirname(__FILE__) . '/xxx.p12');    
$client = new Google_Client();
$scopes = array("https://www.googleapis.com/auth/analytics.readonly");    
if(isset($_SESSION["service_token"])){
    $client->setAccessToken($_SESSION["service_token"]);
}

$credentials = new Google_Auth_AssertionCredentials($client_email,$scopes,$private_key);
$client->setAssertionCredentials($credentials);

if($client->getAuth()->isAccessTokenExpired()){
    $client->getAuth()->refreshTokenWithAssertion($credentials);
}
$_SESSION["service_token"] = $client->getAccessToken();

...

I used this library. I have updated this to the latest in 3 days ago.

I have found similar error posts in stack overflow, but most are caused from server connection problems to 'accounts.google.com', but my server could connect it before. Also I checked host/nslookup too;

# nslookup accounts.google.com
Server:         210.157.3.4
Address:        210.157.3.4#53

Non-authoritative answer:
accounts.google.com     canonical name = accounts.l.google.com.
Name:   accounts.l.google.com
Address: 216.58.220.173

# host accounts.google.com
accounts.google.com is an alias for accounts.l.google.com.
accounts.l.google.com has address 216.58.220.173
accounts.l.google.com has IPv6 address 2404:6800:4004:812::200d

My most concern is that why suddenly error occurred? even though I have not changed any code /library files where I got success in API connection before.

Also I dubious about token problem too, but in my case only 2 or 3 machine has connected api, so it must not be limit of token.

I also checked my server ntp but it worked correct in my server.

I hope anyone had same issues know how to fix it. Thank you always.

--addition 20150505--

Yesterday I tried not through webpage but through command script to access php file, then api worked. Still not get why webpage access suddenly failed, but my problem itself seem to be solved.

cron before

wget http://example.com/analytics-api?f=1

cron after

php /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/get-pageview.php -f1
Community
  • 1
  • 1
user3775389
  • 75
  • 2
  • 10

1 Answers1

0

I had same problem today so

I just disable the firewall and it worked for me

I am using avg antivirus

Mukesh M
  • 2,242
  • 6
  • 28
  • 41