1

Possible duplicate

Hello Friends,

I have refer this Google Drive SDK Exception, actually I got this error

07-18 13:07:49.252: W/System.err(16389): com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized

07-18 13:07:49.252: W/System.err(16389): {
07-18 13:07:49.252: W/System.err(16389):   "code" : 401,
07-18 13:07:49.260: W/System.err(16389):   "errors" : [ {
07-18 13:07:49.260: W/System.err(16389):     "domain" : "global",
07-18 13:07:49.260: W/System.err(16389):     "location" : "Authorization",
07-18 13:07:49.260: W/System.err(16389):     "locationType" : "header",
07-18 13:07:49.260: W/System.err(16389):     "message" : "Invalid Credentials",
07-18 13:07:49.260: W/System.err(16389):     "reason" : "authError"
07-18 13:07:49.267: W/System.err(16389):   } ],
07-18 13:07:49.267: W/System.err(16389):   "message" : "Invalid Credentials"
07-18 13:07:49.267: W/System.err(16389): }

I have been spending 2 days to solve this error but no luck, has anybody implemented Google Drive API to access file and/or upload file?

Please need your help

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159

1 Answers1

0

You need to use a GoogleAccountCredential to authorize and authenticate your requests.

GoogleAccountCredential credential =
    GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);

Drive service = new Drive
    .Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
    .build();

service.files().list().execute();

A quickstart tutorial is available on https://developers.google.com/drive/quickstart-android

Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34
  • 1
    I have also tried using this way but when executing execute() it fails with invalid credentials I don't know why. Thanks for the reply – Pratik Jul 19 '13 at 05:19
  • It's strange. Play services take care of token refreshment and etc. – Burcu Dogan Jul 19 '13 at 09:58
  • Can you post complete flow I think I have wrong way implemented thats why I have getting this error my code was same as I have posted another stack question – Pratik Jul 19 '13 at 12:33
  • The quickstart app on https://developers.google.com/drive/quickstart-android contains the complete flow, fyi. – Burcu Dogan Jul 19 '13 at 21:33