0
在我的網站上,我有一個上傳按鈕,通過API上傳文件到谷歌驅動器。刷新令牌與谷歌API客戶端不工作
這是我的代碼:
$auth_code = GOOGLEDRIVE_AUTH_CODE;
$access_token = GOOGLEDRIVE_ACCESS_TOKEN;
$refresh_token = GOOGLEDRIVE_REFRESH_TOKEN;
$client_id = 'Google_App_Client_ID';
$client_secret = 'Google_App_Client_Secret';
$redirect_uri = 'Redirct_Url';
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->addScope("https://www.googleapis.com/auth/drive");
$service = new Google_Service_Drive($client);
if (isset($access_token) && $access_token) {
$client->setAccessToken($access_token);
if ($client->isAccessTokenExpired()) {
$refresh_token = $client->getRefreshToken();
$client->refreshToken($refresh_token);
$access_token = $client->getAccessToken();
$co->save('GDRIVE_ACCESS_TOKEN',$access_token);
$co->save('GDRIVE_REFRESH_TOKEN',$refresh_token);
}
} else {
$authUrl = $client->createAuthUrl();
}
這一行引發錯誤
$client->refreshToken($refresh_token);
「錯誤刷新的OAuth2令牌,消息: '{ 」錯誤「: 」invalid_grant「}'」
閱讀錯誤消息,聽起來像令牌刷新突然不起作用。就像我說的,這個上傳工具已經好幾個月了。
任何想法?
感謝, Midhun