Patrick Jackson
Patrick Jackson

Reputation: 19436

Google Storage Object download with Java client library on Android

I'm attemping to download an object from GS using the java client library. I get a GoogleAuthException is thrown when getObject.download(out) is called. The exception is null. An empty file is created in the directory. Any ideas on what is going on? Anyone have experience with these libs??

     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) {

        }

Upvotes: 1

Views: 1257

Answers (1)

Patrick Jackson
Patrick Jackson

Reputation: 19436

Turns out I was using a older version of GoogleAccountCredential which did not throw the correct exceptions. Once this was fixed, the exception being thrown was a UserRecoverableAuthException and the permission intent could be lauched. Works like a champ now.

Upvotes: 1

Related Questions