如何修复致命错误:找不到类'Google_Service_Drive_ParentReference'?

时间:2016-03-21 08:33:15

标签: php google-api

我收到了致命错误:当我尝试将文件上传到Google云端硬盘时,找不到“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();
}

}

2 个答案:

答案 0 :(得分:1)

api肯定简化了整个过程。添加字段'父母'在文件夹创建期间

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

答案 1 :(得分:1)

你不需要再次调用这个类就像这样做

$file = new Google_Service_Drive_DriveFile();
$file->setName($filename);
$file->setDescription($description);
$file->setParents(array($parentId));