在quickstart之后,我已启用API并在步骤2中安装了Google客户端库。我想从此page运行代码。
require 'vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName('Google Drive API PHP Quickstart');
$client->setScopes(Google_Service_Drive::DRIVE);
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$client->setPrompt('select_account consent');
$driveService = new Google_Service_Drive( $client );
$fileMetadata = new Google_Service_Drive_DriveFile( array(
'name' => 'Invoices',
'mimeType' => 'application/vnd.google-apps.folder' ) );
$file = $driveService->files->create( $fileMetadata, array( 'fields' => 'id' ) );
printf( "Folder ID: %s\n", $file->id );
我认为问题在于$ client变量的创建。我想直接从GCP运行脚本,而无需进行任何交互,只需在Google云端硬盘中创建一个文件夹。有人知道完成此操作的简单方法吗?
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file "credentials.json"
我需要创建一个“ credentials.json”文件来在自己的驱动器中创建一个文件夹吗?