i am trying to access Google Analytics Account and its Data while the User is Offline. For some reason am not able to get the refresh_token.
This is what i am doing.
//If No token is set generate Auth URL
if (!$client->getAccessToken()) {
$authUrl = $client->createAuthUrl();
header('Location: $authUrl'));
}
This sends me to Google and i Grant access to the Account
//Settings
$client->setClientId('
70181844.apps.googleusercontent.com');
$client->setClientSecret('Co81SxK65fxAFHovtG0ji');
$client->setRedirectUri('
http://localhost/gitgrow1/index.php');
$client->setDeveloperKey('AIzaTSPKHNh7pMSCJ95SrGkxm2E92eV4r75Y');
$client->setScopes(array('
https://www.googleapis.com/auth/userinfo.profile',
'
https://www.googleapis.com/auth/userinfo.email',
'
https://www.googleapis.com/auth/analytics.readonly'));
$client->setAccessType('offline');
$client->setApprovalPrompt('auto');
Now if Google returns a Code i authenticate and try to get the Token.
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
echo "<pre>";
print_r($_GET);
print_r(json_decode($client->getAccessToken()));
if (!$client->getAccessToken()) {
$authUrl1 = $client->revokeToken();
print_r($authUrl1);
}
echo "</pre>";
}
This only Gives me the following
Array
(
[code] => kACAH-1Ng2_8mPWAXS1-rUk8Z2q8ALn_FCErtp2lrYyvrSBCpo2J9Ahjpo7MjO6LNDrK9cxePMc5eGwUGGZ-B7Qshh1eSmEzwizNtpB9PTVJZ-GdTKQxXR-n18
)
stdClass Object
(
[access_token] => ya29.AHES6ZTisW_qS-yG9EU9GClF8utib0BnA81oT_voECjwvCZ4HleRCQ
[token_type] => Bearer
[expires_in] => 3600
[id_token] => eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXVkIjoiNzAxODE4MjcxNjQ0LmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiY2lkIjoiNzAxODE4MjcxNjQ0LmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiaWQiOiIxMTAwODQzMzA1OTM4MDAzOTY3NjQiLCJlbWFpbCI6ImhhcnNoYUBtaW5rNy5jb20iLCJ2ZXJpZmllZF9lbWFpbCI6InRydWUiLCJ0b2tlbl9oYXNoIjoiaExkN3RnSnJrZGpITExObWZrZktvZyIsImhkIjoibWluazcuY29tIiwiaWF0IjoxMzQwNDU0ODc2LCJleHAiOjEzNDA0NTg3NzZ9.Q691XUJBwC6EEKUv3wy94Ab76gL6wZz3lcwSHlixLyjMgGBPWRzwMQcTMyrWoh-V9nxhp3nEaJZ1KfzI9j4ufUdpdX4tWiz8shdhoNJJHbSYKeEer3foKyjv_zped55BLbVA2IcJT9Tnw84f1toOqrVzDDqLsrWLQbtPFY49dak
[created] => 1340455163
)
I am expecting a refresh_token here instead of id_token.
Can someone guide me what i am doing wrong ? I am using the official PHP Client for google API