简体   繁体   中英

google drive quota using android api for drive

How can I get the amount of storage and used quota of a user's google drive account? I'm building an android app with the android api for drive: https://developers.google.com/drive/android/ .

I couldn't find any method that could return the details for me, but, I believe I have to use call the rest api like shown here: https://developers.google.com/drive/v2/reference/about/get . How do I retrieve the drive service instance? I already have mGoogleAuthClient which can talk to drive APIs. Any help?

Something like this:

com.google.android.gms.common.api.GoogleApiClient mGAC = new GoogleApiClient
  .Builder(this)
  .addApi(com.google.android.gms.drive.Drive.API)
  .addScope(com.google.android.gms.drive.Drive.SCOPE_FILE)
  .addConnectionCallbacks(this)
  .addOnConnectionFailedListener(this)
  .setAccountName(email)
  .build(); 

com.google.api.services.drive.Drive mGSvc = new Drive
  .Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(),
  GoogleAccountCredential
    .usingOAuth2(this, Collections.singletonList(DriveScopes.DRIVE_FILE))
    .setSelectedAccountName(email)
  ).build();
  }

gives you access to both the GDAA and the REST Apis.

But remember a few things:

That means that mixing the two involves some timing consideration .

Good Luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM