本文整理汇总了Java中com.google.api.services.drive.model.Permission.setRole方法的典型用法代码示例。如果您正苦于以下问题:Java Permission.setRole方法的具体用法?Java Permission.setRole怎么用?Java Permission.setRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.drive.model.Permission
的用法示例。
在下文中一共展示了Permission.setRole方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPermission
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
private boolean setPermission(Track track, String tableId) throws IOException, GoogleAuthException {
boolean defaultTablePublic = PreferencesUtils.getBoolean(context,
R.string.export_google_fusion_tables_public_key,
PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
if (!defaultTablePublic) {
return true;
}
GoogleAccountCredential driveCredential = SendToGoogleUtils.getGoogleAccountCredential(
context, account.name, SendToGoogleUtils.DRIVE_SCOPE);
if (driveCredential == null) {
return false;
}
Drive drive = SyncUtils.getDriveService(driveCredential);
Permission permission = new Permission();
permission.setRole("reader");
permission.setType("anyone");
permission.setValue("");
drive.permissions().insert(tableId, permission).execute();
shareUrl = SendFusionTablesUtils.getMapUrl(track, tableId);
return true;
}
示例2: insertPermission
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
/**
* Insert a new permission.
*
* @param service
* Drive API service instance.
* @param fileId
* ID of the file to insert permission for.
* @return The inserted permission if successful, {@code null} otherwise.
*/
private static Permission insertPermission(Drive service, String fileId,
String value, String type, String role) {
Permission newPermission = new Permission();
newPermission.setValue(value);
newPermission.setType(type);
newPermission.setRole(role);
try {
return service.permissions().insert(fileId, newPermission)
.execute();
} catch (IOException e) {
System.out.println("An error occurred: " + e);
}
return null;
}
示例3: shareWithUser
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
public void shareWithUser(String fileId, String userEmail, boolean canWrite) throws IOException {
Permission permission = new Permission();
permission.setValue(userEmail);
permission.setType("user");
permission.setRole(canWrite ? "writer" : "reader");
drive.permissions().insert(fileId, permission).execute();
}
示例4: shareWithAnyone
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
public void shareWithAnyone(String fileId, boolean canWrite, boolean withLink) throws IOException {
Permission permission = new Permission();
permission.setValue("");
permission.setType("anyone");
permission.setRole(canWrite ? "writer" : "reader");
permission.setWithLink(withLink);
drive.permissions().insert(fileId, permission).execute();
}
示例5: executeDrivePermission
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
protected void executeDrivePermission(Drive drive, String fileId, String email)
throws ODKExternalServiceException {
oauth2logger.info("Switching file permissions");
if (email == null) {
throw new ODKExternalServiceException(NO_EMAIL_SPECIFIED_ERROR);
}
try {
String userName = email.substring(SecurityUtils.MAILTO_COLON.length());
Permission newPermission = new Permission();
newPermission.setKind("drive#permission");
newPermission.setRole("owner");
newPermission.setType("user");
newPermission.setEmailAddress(userName);
// NOTE: Dropped the check because name was not a good value to compare
Drive.Permissions.Create createPerm = drive.permissions().create(fileId, newPermission);
// ownership transfer now requires notification e-mail
// createPerm.setSendNotificationEmail(false);
createPerm.setTransferOwnership(true);
Permission response = createPerm.execute();
if (response == null) {
oauth2logger.error(NO_PERM_RETURNED);
throw new ODKExternalServiceException(NO_PERM_RETURNED);
}
} catch (IOException e) {
throw new ODKExternalServiceException(e);
}
}
示例6: insertPermission
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
/**
* Insert a new permission.
*
* @param service Drive API service instance.
* @param fileId ID of the file to insert permission for.
* @param value User or group e-mail address, domain name or
* {@code null} "default" type.
* @param type The value "user", "group", "domain" or "default".
* @param role The value "owner", "writer" or "reader".
* @return The inserted permission if successful, {@code null}
* otherwise.
* @throws UploadException
*/
public static Permission insertPermission(Drive service, String fileId,
String value, String type, String role) throws UploadException {
Permission newPermission = new Permission();
newPermission.setValue(value);
newPermission.setType(type);
newPermission.setRole(role);
try {
return service.permissions().insert(fileId, newPermission)
.execute();
} catch (IOException e) {
throw new UploadException(e);
}
}
示例7: insertPermission
import com.google.api.services.drive.model.Permission; //导入方法依赖的package包/类
/**
* Insert a new permission.
*
* @param service
* Drive API service instance.
* @param fileId
* ID of the file to insert permission for.
* @param value
* User or group e-mail address, domain name or {@code null}
* "default" type.
* @param type
* The value "user", "group", "domain" or "default".
* @param role
* The value "owner", "writer" or "reader".
* @return The inserted permission if successful, {@code null} otherwise.
*/
private static Permission insertPermission(Drive service, String fileId) {
Permission newPermission = new Permission();
newPermission.setValue("[email protected]");
newPermission.setType("user");
newPermission.setRole("writer");
try {
return service.permissions()
.insert(fileId, newPermission)
.execute();
} catch (IOException e) {
Log.e("myStress","Error on setting Permission for GDrive-File: " + e.getMessage());
}
return null;
}