1
votes

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

1
Please post your code. - JunYoung Gwak

1 Answers

0
votes

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