just started using google admin SDK,trying to retrieve specific user's infomation. i keep getting the same error over and over
[29-May-2015 14:41:18 Africa/Tunis] PHP Fatal error: Uncaught
exception 'Google_Auth_Exception' with message 'Error refreshing the
OAuth2 token, message: '{ "error" : "invalid_grant"
during my research i found that it's mostly a syncing problem(server time) but my web app is hosted on a third party server.checked my service account credentials
Ps: don't know if it matters but the server's time zone is GMT+1
`
<?php
require 'src/Google/autoload.php';
session_start();
$timestamp = $_SERVER['REQUEST_TIME'];
echo gmdate("Y-m-d\TH:i:s\Z", $timestamp);
$service_account_name = "xx";
$key_file_location = "yyy.p12";
$client = new Google_Client();
$client->setApplicationName("Members");
$directory = new Google_Service_Directory($client);
if (isset($_SESSION['service_token']) && $_SESSION['service_token']) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
// Replace this with the email address from the client.
$service_account_name,
// Replace this with the scopes you are requesting.
array('https://www.googleapis.com/admin/directory/v1/users'),
$key,
'notasecret'
);
$cred->sub = "admin-email";
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
$email = "personto lookfor-email";
$r = $dir->users->get($email);
if($r) {
echo "Name: ".$r->name->fullName."<br/>";
echo "Suspended?: ".(($r->suspended === true) ? 'Yes' : 'No')."<br/>";
echo "Org/Unit/Path: ".$r->orgUnitPath."<br/>";
} else {
echo "User does not exist: $email<br/>";
// if the user doesn't exist, it's safe to create the new user
}
`