通过Google Drive API将文件共享级别设置为“有链接的任何人”

时间:2012-06-22 11:36:41

标签: google-drive-api

怎么做?我应该使用Google Docs ACL以及如何配置此类ACL吗?

4 个答案:

答案 0 :(得分:20)

您必须设置以下参数:

private Permission insertPermission(Drive service, String fileId) throws Exception{
   Permission newPermission = new Permission();
   newPermission.setType("anyone");
   newPermission.setRole("reader");
   newPermission.setValue("");
   newPermission.setWithLink(true);
   return service.permissions().insert(fileId, newPermission).execute();
}

答案 1 :(得分:4)

使用此方法可让任何人都可以看到您的文件:

private static Permission insertPermission(Drive service, String fileId) throws IOException
{
    Permission newPermission = new Permission();
    newPermission.setType("anyone");
    newPermission.setRole("reader");

    return service.permissions().insert(fileId, newPermission).execute();
}

更多详情here

答案 2 :(得分:1)

答案 3 :(得分:0)

对于Google Drive API V3,请使用此方法使文件对所有人可见:

    private Permission InsertAnyonePermissionToDownload(Google.Apis.Drive.v3.DriveService service, String fileId)
    {
        Permission newPermission = new Permission();
        newPermission.Type = "anyone";
        newPermission.Role = "reader";
        return service.Permissions.Create(newPermission, fileId).Execute();
    }