问题描述
我按照 https://developers.google.com/drive/quickstart- 下的所有步骤收听安卓有用!但是如果我要将给定的代码/包合并到另一个项目,我会得到
I followed all steps listen under https://developers.google.com/drive/quickstart-androidIt 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 answerGoogle 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!