【发布时间】:2018-09-09 07:19:16
【问题描述】:
如何将文件上传到 google drive -Google drive API 中的特定文件夹? 我有这段代码,它将我的文件上传到谷歌驱动器的主文件夹。
$client->setAccessToken($_SESSION['accessToken']);
$service = new Google_DriveService($client);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file = new Google_DriveFile();
foreach ($files as $file_name) {
$file_path = 'files/'.$file_name;
$mime_type = finfo_file($finfo, $file_path);
$file->setTitle($file_name);
$file->setDescription('This is a '.$mime_type.' document');
$file->setMimeType($mime_type);
$service->files->insert($file, array(
'data' => file_get_contents($file_path),
'mimeType' => $mime_type
));
}
【问题讨论】:
-
嗨,您必须使用父文件夹 ID 数组设置
parents属性(请参阅此处的属性列表,以创建文件,developers.google.com/drive/api/v3/reference/files/create)
标签: php google-drive-api