Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Drive API: getting Sys.err UserRecoverableAuthIOException if i merge code to other projects

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

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

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

Any ideas would be helpful. Thank you.

like image 985
benjamin ali Avatar asked Feb 28 '13 17:02

benjamin ali


1 Answers

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.

Sample code -

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);
}
like image 154
jaibatrik Avatar answered Nov 05 '22 17:11

jaibatrik