可能重复
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来访问文件和/或上传文件?
请需要你的帮助
答案 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();
上提供了快速入门教程