1

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?

seanpj
  • 6,735
  • 2
  • 33
  • 54
user979799
  • 53
  • 6

1 Answers1

0

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.

Community
  • 1
  • 1
seanpj
  • 6,735
  • 2
  • 33
  • 54
  • Thank you so much for a quick response. I tried using REST APIs in my android application but it's not working. I'm refering this sample code : https://developers.google.com/drive/web/quickstart/java. The reason of failure is `Credential credential = new AuthorizationCodeInstalledApp( flow, new LocalServerReceiver()).authorize("user");` This authorize opens the browser in web application to authorize the user credentials but in Android browser is not opening for authenticaiton. This sample code works fine in web applicaiton. – user979799 Aug 10 '15 at 01:08
  • I was referring to a native Android App,not Android browser. See these 2 demos the [GDAADemo](https://github.com/seanpjanson/GDAADemo) and the [RESTDemo](https://github.com/seanpjanson/RESTDemo). – seanpj Aug 10 '15 at 16:16
  • Thank you so much. This is what I was looking for. – user979799 Aug 11 '15 at 15:09