I'm doing some experimenting with the Google Analytics API and it's coming along nicely (just following their Hello Analytics turorial for now). The code runs fine up to the point where I'm at when i run it on my old dummy domain, but when I try to do it fromm a site I'm currently developing (with joomla) I get problems with the http-requests.
I give the user a link to google where I can choose google account and grant access to GA etc and when it redirects to my site I get nothing. It loads for a while then sends me to my sites 404 page.
My code looks like this (it's inside the default.php in a view of a component. I took away the defined(j_exec) or die() for testing purposes):
<?php
require_once 'libraries/google-api-php-client/src/Google_Client.php';
require_once 'libraries/google-api-php-client/src/contrib/Google_AnalyticsService.php';
require_once 'libraries/google-api-php-client/src/contrib/Google_PlusService.php';
$session = JFactory::getSession();
$client = new Google_Client();
//$client->setAccessType('online');
$client->setApplicationName('sdffdgdfg');
$client->setClientId('my id ;)');
$client->setClientSecret('dsfdsf');
$client->setRedirectUri('asdsdf');
$client->setDeveloperKey('fdfg');
$client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
// Set the client libraries to convert all the API responses from associative arrays into objects.
$client->setUseObjects(true);
//$plus = new Google_PlusService($client);
if( isset( $_GET['code'] ) ){
$client->authenticate($_GET['code'] );
$session->set('token', $client->getAccessToken());
//i took away the redirect here cuz i wanted to see that the code actually came :)
}
$token = $session->get('token');
if( isset( $token ) ){
$client->setAccessToken($session->get('token'));
}
if( !$client->getAccessToken() ){
$authUrl = $client->createAuthUrl();
print "<a class ='login' href='$authUrl'>Connect me!</a>";
}else{
echo "WE'RE IN!!";
//$analytics = new apiAnalyticsService($client);
//runMainDemo($analytics);
}
?>
The problem stops if I comment the line $client->authenticate($_GET['code'] ); so I've followed that trail and finally come to a line saying
$request = Google_Client::$io->makeRequest(new Google_HttpRequest(self::OAUTH2_TOKEN_URI, 'POST', array(), array(
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUri,
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret
)));
This line resides in Google_OAuth2.php line 96. So something goes wrong with the request and it time out. What can I do about it? This is pretty much as far as my own problem solving takes me so I really need some help with this! Could it be something to do with joomla? Or my server configuration? (Not same as my dummy domain..)
Thanks a lot in advance!!