我正在尝试使用 java 客户端库从 GS 下载对象。调用 getObject.download(out) 时会引发 GoogleAuthException。异常为空。在目录中创建一个空文件。关于发生了什么的任何想法?有人对这些库有经验吗?
GoogleAccountCredential credential=
GoogleAccountCredential.usingOAuth2(FirefighterLog.getInstance(),
"https://www.googleapis.com/auth/devstorage.read_only");
credential.setAccountName(name);
com.google.api.services.storage.Storage storageService =
new com.google.api.services.storage.Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("myApp").build();
try {
Get getObject=storageService.objects().get("myBucket", "myObject");
String appPath = FirefighterLog.getInstance().getApplicationContext().getFilesDir ().getAbsolutePath();
java.io.File parentDir = new java.io.File(appPath);
OutputStream out = new FileOutputStream(new java.io.File(parentDir,"myFileName" ));
gettObject.getMediaHttpDownloader().setDirectDownloadEnabled(true);
getObject.download(out);
} catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
showGooglePlayServicesAvailabilityErrorDialog(
availabilityException.getConnectionStatusCode());
} catch (UserRecoverableAuthIOException userRecoverableException) {
startActivityForResult(
userRecoverableException.getIntent(), GS_AUTH_RESULT);
} catch (IOException e) {
}