gpt4 book ai didi

php - 如何修复 fatal error : Class 'Google_Service_Drive_ParentReference' not found?

转载 作者:行者123 更新时间:2023-12-02 15:21:33 25 4
gpt4 key购买 nike

我收到 fatal error :当我尝试将文件上传到谷歌驱动器时找不到类“Google_Service_Drive_ParentReference”。我该如何解决?我认为 Api 错过了 Drive.php

中的类“ Google_Service_Drive_ParentReference
insertFile($service, $title, $description, $parentId, $mimeType, $filename) {
$file = new Google_Service_Drive_DriveFile();
$file->setName($title);
$file->setDescription($description);
$file->setMimeType($mimeType);

// Set the parent folder.
if ($parentId != null) {
$parent = new Google_Service_Drive_ParentReference();
$parent->setId($parentId);
$file->setParents(array($parent));
}

try {
$data = file_get_contents($filename);

$createdFile = $service->files->create($file, array(
'data' => $data,
'mimeType' => $mimeType,
));

// Uncomment the following line to print the File ID
// print 'File ID: %s' % $createdFile->getId();

return $createdFile;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}

最佳答案

api 确实简化了整个过程。在文件夹创建过程中添加字段'parents'

        $folder = new Google_Service_Drive_DriveFile(array(
'name' => 'sub-folder-name',
'mimeType' => 'application/vnd.google-apps.folder',
'parents' => array('parent-id')
);

关于php - 如何修复 fatal error : Class 'Google_Service_Drive_ParentReference' not found?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36126173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com