3

My android app needs to upload files to google drive.

Upon first look I decided to use the Google Drive Android Apis but there seems to be no method to upload audio files.

So I decided to use the Google Drive REST Apis but now I have problems authorizing my app. The docs say to use Google Api Client Library for Java, and gives out an example:

GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);
credential.setSelectedAccountName(accountName);
Drive service = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();

and then also:

try {
    // Try to perform a Drive API request, for instance:
    // File file = service.files().insert(body, mediaContent).execute();
} catch (UserRecoverableAuthIOException e) {
    startActivityForResult(e.getIntent(), COMPLETE_AUTHORIZATION_REQUEST_CODE);
}

First of all, how am I supposed to provide an accountName if I'm trying to just send an authorization request? I have an Activity with a sign-in button and when I click it, I wanna ask the auth server the token (using the Drive Apis from Android this was pretty easy, just needed to send an Intent gotten from my GoogleSignIn instance).

Second, the service.files().create method (I think the insert method is from an older version) doesn't throw a UserRecoverableAuthIOException, so I can't really extract the intent from it like e.getIntent(). So I can't sign in.

I'm really stuck and I've tried a bunch of things but I really don't know how to proceed.

(tl;dr) How can I:

  1. Authorize my app to access my google drive files
  2. Upload .mp4 files to that google drive account

???

Thank you for your time.

ovalb
  • 555
  • 6
  • 15
  • 1
    for authorization check this https://developers.google.com/drive/android/auth and for upload the file check this https://stackoverflow.com/questions/27409953/uploading-video-to-google-drive-programmatically-android-api – Thelouras Nov 18 '18 at 17:19

0 Answers0