【问题标题】:Google Storage Object download with Java client library on Android在 Android 上使用 Java 客户端库下载 Google 存储对象
【发布时间】:2012-11-19 08:20:51
【问题描述】:

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

        }

【问题讨论】:

    标签: android google-api-java-client google-cloud-storage google-play-services


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2015-12-08
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    相关资源
    最近更新 更多