希望对我们的Google云端硬盘API提供一些支持。我们有一个脚本,可在添加新客户端时创建Google云端硬盘文件夹。这个剧本工作了6个多月,突然爆发了。我们得到的错误是:
Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'
我想强调一下,我们的代码中没有任何内容发生变化。令牌只是停止对所有用户进行身份验证。
我们疯狂地想弄清楚为什么这会“随机”发生一天。任何帮助是极大的赞赏。
try {
require '/var/www/html/s2/googledrive/vendor/autoload.php';
define('APPLICATION_NAME', 'Drive API Quickstart');
define('CREDENTIALS_PATH', '~/.credentials/dirrec.json');
define('CLIENT_SECRET_PATH', '/var/www/html/client_secret.json');
define('SCOPES', 'https://www.googleapis.com/auth/drive');
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
require_once('include/upload_file.php');
$file = new UploadFile();
//get the file location
$file->temp_file_location = 'custom/modules/Accounts/dirrec.json';
$accessToken = $file->get_file_contents();
$client->setAccessToken($accessToken);
$service = new Google_Service_Drive($client);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents('custom/modules/Accounts/dirrec.json', $client->getAccessToken());
}