使用GoogleDrive API列出GoogleApps用户的文件时出现了一个问题。
public void getFiles(String serviceAccount) throws Exception {
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccount)
.setServiceAccountScopes(Collections.singleton(DriveScopes.DRIVE))
.setServiceAccountUser("xxx@xxx.com")
.setServiceAccountPrivateKeyFromP12File(new java.io.File(new URI(ServiceTest.class.getClassLoader().getResource("googledrive.p12").toString())))
.build();
credential.refreshToken();
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).setApplicationName("GoogleDrive").build();
FileList result = service.files().list().setMaxResults(1000).execute();
List<File> files = result.getItems();
if (files != null && files.size() > 0) {
for (File file : files) {
System.out.println(file.getTitle()+","+file.getId()+","+file.getExportLinks());
}
}
}
响应很好,我可以成功获得所有文件,包括fileid,fiename,parentid .... 但是所有文件的exportLinks都是NULL(当我使用3-legged oAuth时,大多数这些文件都有exportLinks。)
任何人都可以帮助我吗?