Android版Google Drive API的凭据无效

时间:2013-07-18 07:48:11

标签: android oauth google-drive-api

可能重复

Hello Friends,

我已经引用了此Google Drive SDK Exception,实际上我收到了此错误

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): }

我花了两天的时间来解决此错误,但没有运气,有没有人实施Google Drive API来访问文件和/或上传文件?

请需要你的帮助

1 个答案:

答案 0 :(得分:0)

您需要使用GoogleAccountCredential来授权和验证您的请求。

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

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

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

https://developers.google.com/drive/quickstart-android

上提供了快速入门教程