6

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

 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

我在清单中做错了什么还是应该在 Api 控制台中更改某些内容?

在stackoverflow下发现只有一个线程没有任何答案 Google Drive Authentication Exception - Needs Permission?(v2)

任何想法都会有所帮助。谢谢你。

4

1 回答 1

21

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

示例代码 -

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);
}
于 2013-02-28T18:30:40.070 回答