【发布时间】:2015-06-28 06:49:25
【问题描述】:
我无法将文件上传到特定的驱动器文件夹。
我的 Java 代码是:
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
try {
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(IRingeeConstants.SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Collections.singleton(DriveScopes.DRIVE_APPDATA)).setServiceAccountPrivateKeyFromP12File(new java.io.File("G:\\Ringee-1a1f1b786226.p12")).build();
Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).setApplicationName(IRingeeConstants.APPLICATION_NAME).build();
File body = new File();
body.setTitle("ringee");
body.setDescription("ringeeapp");
body.setMimeType("application/vnd.google-apps.folder");
java.io.File fileContent = new java.io.File("G:\\document.txt");
FileContent mediaContent = new FileContent("text/plain", fileContent);
File file = service.files().insert(body, mediaContent).execute();
System.out.print("file id is :" + file.getId());
Permission newPermission = new Permission();
// for showing files in browser that reason only using additional
// permission
newPermission.setValue(IRingeeConstants.USER_ACCOUNT_EMAIL);
newPermission.setType("owner");
newPermission.setRole("writer");
service.permissions().insert(file.getId(), newPermission).execute();
getFileByFileId(service, file.getId());
} catch (Exception e) {
e.printStackTrace();
}
文件上传到根文件夹。这是为什么呢?
如何解决这个问题..
【问题讨论】:
标签: java google-drive-api google-drive-android-api