public void shareFile(String fileId, GranteeType granteeType, GranteeRoleType granteeRoleType, String email) { BatchRequest batch = new BatchRequest(getHttpTransport(), (HttpRequestInitializer) driveService.getGoogleClientRequestInitializer()); Permission userPermission = new Permission() .setType(granteeType.getValue()) .setRole(granteeRoleType.getValue()) .setEmailAddress(email); try { driveService.permissions().create(fileId, userPermission) .setFields("id") .queue(batch, new GoogleDriveJsonBatchCallback<Permission>()); batch.execute(); } catch (IOException e) { LOGGER.error(e); } }
/** * An accessor for creating requests from the Permissions collection. * * <p>The typical use is:</p> * <pre> * {@code Drive drive = new Drive(...);} * {@code Drive.Permissions.List request = drive.permissions().list(parameters ...)} * </pre> * * @return the resource collection */ public Permissions permissions() { return new Permissions(); }
public void shareFile(File file, String to) throws IOException { BatchRequest batch = drive.batch(); Permission userPermission = new Permission() .setType("user") .setRole("writer") .setValue(to); drive.permissions().insert(file.getId(), userPermission) .setSendNotificationEmails(true) .setFields("id") .queue(batch, callback); batch.execute(); }