Google云端硬盘文件未设置到期时间权限

时间:2018-07-12 06:10:05

标签: php google-drive-api

$newPermission = new Google_Service_Drive_Permission();

$newPermission->setEmailAddress($value); 
$newPermission->setExpirationTime('2018-07-13T16:00:00+05:30');
$newPermission->setType($type);
$newPermission->setRole($role);

我的驱动器存储未存储ExpirationTime

1 个答案:

答案 0 :(得分:1)

v3中有一些小的更改。查看此链接https://developers.google.com/drive/api/v3/reference/permissions/create https://developers.google.com/drive/api/v3/manage-sharing https://gist.github.com/bshaffer/9bb2cdccd315880ab52f#file-drive-php-L954

 insertPermission($service, $fileId, $value, $type, $role) { 
        $newPermission = new Google_Service_Drive_Permission(array(
            'type' => $type,
            'role' => $role,
            'emailAddress' => $value,
            'expirationTime' => '2018-08-18T16:00:00+05:30'
        ));
        try { 
            $created =  $service->permissions->create($fileId, $newPermission); 
            $permissionsId = $created->id;
            $updatedPermission = new Google_Service_Drive_Permission(array(
                'role' => $role,
                'expirationTime' => '2018-08-18T16:00:00+05:30'
            ));
            $updated =  $service->permissions->update($fileId, $permissionsId , $updatedPermission, array(
                'fields' => 'id, expirationTime'
            )); 
            $expirationTime = $updated->expirationTime;
            echo "expirationTime : " . $expirationTime;
        } catch (Exception $e) { 
            print "An error occurred: " . $e->getMessage(); 
        }
        return NULL; 
    }