1

我正在尝试使用 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) {

        }
4

1 回答 1

1

原来我使用的是旧版本的 GoogleAccountCredential,它没有抛出正确的异常。修复此问题后,引发的异常是 UserRecoverableAuthException,并且可以启动权限意图。现在像冠军一样工作。

于 2012-12-01T06:33:44.560 回答