Android Drive API:如果我将代码合并到其他项目,则会获取 Sys.err UserRecoverableAuthIOException [英] Android Drive API: getting Sys.err UserRecoverableAuthIOException if i merge code to other projects

查看:8
本文介绍了Android Drive API:如果我将代码合并到其他项目,则会获取 Sys.err UserRecoverableAuthIOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 https://developers.google.com/drive/quickstart- 下的所有步骤收听安卓有用!但是如果我要将给定的代码/包合并到另一个项目,我会得到

I followed all steps listen under https://developers.google.com/drive/quickstart-android It works! But if im going to merge the given code/package to an other project, im getting

 W/System.err(793): com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
 W/System.err(793): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
 W/System.err(793): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
 W/System.err(793): at com.drive.main.MainActivity$GetToken.doInBackground(MainActivity.java:139)
 W/System.err(793): at com.drive.main.MainActivity$GetToken.doInBackground(MainActivity.java:1)
 W/System.err(793): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
 W/System.err(793): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
 W/System.err(793): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
 W/System.err(793): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
 W/System.err(793): at java.lang.Thread.run(Thread.java:856)
 I/System.out(793): An error occurred: com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException

我是在 Manifest 中做错了什么,还是应该在 Api 控制台中进行更改?

Am I doing something wrong in the Manifest or should i change something in the Api Console?

stackoverflow下只找到一个线程没有任何答案Google Drive 身份验证异常 - 需要权限?(v2)

Found only one thread under stackoverflow without any answer Google Drive Authentication Exception - Needs Permission? (v2)

任何想法都会有所帮助.谢谢.

Any ideas would be helpful. Thank you.

推荐答案

您应该捕获 UserRecoverableAuthException 并在 catch 块中,通过以下方式从异常中恢复 Intent调用 UserRecoverableAuthException#getIntent().启动该意图,将用户带到您的应用的 OAuth2 权限页面.

You should catch the UserRecoverableAuthException and in the catch block, you recover the Intent from the exception by calling UserRecoverableAuthException#getIntent(). Start that intent to take user to the OAuth2 permission page for your app.

示例代码 -

try {
    Drive service = Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
        .build();
    // Do whatever you want with the Drive service
} catch (UserRecoverableAuthIOException e) {
    startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}

这篇关于Android Drive API:如果我将代码合并到其他项目,则会获取 Sys.err UserRecoverableAuthIOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆