我正在尝试使用PHP将文件上传到Google云端硬盘,我已经复制了官方Google代码(https://developers.google.com/drive/api/v3/manage-uploads) 当我从CLI运行文件时,出现此错误:
PHP Fatal error: Uncaught Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission: Request had insufficient authentication scopes."
}
],
"code": 403,
"message": "Insufficient Permission: Request had insufficient authentication scopes."
}
}
代码:
//Omitted code can be found here -> https://developers.google.com/drive/api/v3/quickstart/php
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Drive($client);
$fileMetadata = new Google_Service_Drive_DriveFile(array('name' => 'backup.sql'));
$content = file_get_contents('/var/www/html/backup-db/backup.sql');
$file = $service->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'application/sql',
'uploadType' => 'multipart',
'fields' => 'id'));
printf("File ID: %s\n", $file->id);