使用Google提供的PHP客户端库。还在Google API控制台中使用Web应用程序。当我尝试刷新我的令牌时,返回“Google_AuthException”并显示消息'错误刷新OAuth2令牌,消息:'{ “error”:“invalid_grant”“。请帮我刷新我的令牌
这在我的示例代码中
ini_set("memory_limit", -1);
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
$client->setApplicationName("Google+ PHP Starter Application");
$client->setClientId('XXXXXXXXXXX');
$client->setClientSecret('XXXXXXXXXX');
$client->setRedirectUri('http://localhost:1134/Google%20APIs/index.php');
$client->setAccessType("offline");
$client->setApprovalPrompt("force");
$SCOPES = array(
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile');
$client->setScopes($SCOPES);
$drive = new Google_DriveService($client);
$token ='{"access_token":"XXXXXXXX","token_type":"Bearer","expires_in":3600,"id_token":"XXXXXXXXXXXXXXXXXXXXXXX","refresh_token":"XXX","created":1396703189}';
$client->setAccessToken($token);
if ($client->isAccessTokenExpired()) {
$client->refreshToken("1\/ccccccxxxxx");
}
if ($client->getAccessToken()) {
$user = $client->about;
$ret = retrieveAllFiles($drive);
//var_dump($ret);
} else {
$authUrl = $client->createAuthUrl();
}
function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$result = array_merge($result, $files['items']);
$pageToken = $files['nextPageToken'];
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
return $result;
}