这是我的代码:
public void getDriveService() throws GeneralSecurityException, IOException, URISyntaxException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
ArrayList<String> scopes = new ArrayList<String>();
scopes.add(DriveScopes.DRIVE);
scopes.add(DriveScopes.DRIVE_APPDATA);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("akh....@smart-spark-13..5.iam.gserviceaccount.com")
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(File p12)
.build();
com.google.api.services.drive.Drive service = new com.google.api.services.drive.Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential)
.build();
//return service;
mydrive = service;
}
这可能与文件权限有关,但我可以使用getThumbnailUrl()查看文件的缩略图链接,但是通过getDownloadUrl()下载会抛出异常;