Google云端硬盘授权问题Android-com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException

时间:2015-09-26 08:37:14

标签: android google-drive-api google-drive-android-api

在我的应用程序中有两个文件,一个片段和一个activity.In片段的onResume()我正在调用活动进行授权。

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    // Initialize credentials and service object.
    SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
    credential = GoogleAccountCredential.usingOAuth2(
            getApplicationContext(), Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff())
            .setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

    mService = new com.google.api.services.drive.Drive.Builder(
            transport, jsonFactory, credential)
            .setApplicationName("AppName")
            .build();
}

在这个简介中,我将在SharedPreference中保存emailId。这是有效的。

然后我试图访问片段文件中googledrive的所有文件夹。

 private void listFolder(final String folderId, final String emal)
        throws IOException {
    mGOOSvc = new com.google.api.services.drive.Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(),
            GoogleAccountCredential.usingOAuth2(this.getActivity(), Collections.singletonList(DriveScopes.DRIVE))
                    .setSelectedAccountName(emal)
    ).build();
    final ArrayList<String> al = new ArrayList<String>();
    final ArrayList<String> alIds = new ArrayList<String>();
    alIds.clear();
    request = mGOOSvc.children().list(folderId);
    new AsyncTask<String, String, String>() {
        @Override
        protected String doInBackground(String... params) {


            do {
                try {

                    ChildList children = request.execute();
                    for (ChildReference child : children.getItems()) {

                        String childId = child.getId();
                        File file = mGOOSvc.files().get(childId).execute();

                        if (!file.getExplicitlyTrashed() && file.getMimeType().equals("application/vnd.google-apps.folder")) {

                            al.add(file.getTitle());
                            alIds.add(file.getId());

                        }
                    }
                    request.setPageToken(children.getNextPageToken());
                } catch (Exception e) {
                    System.out.println("An error occurred: " + e.getMessage());
                    request.setPageToken(null);
                }
            } while (request.getPageToken() != null &&
                    request.getPageToken().length() > 0);

            return null;
        }


    }.execute();
}

它在ChildList上显示异常children = request.execute();: com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException ..

(Interseting thing它与我的一个GoogleDrive帐户完美配合。但是在其他帐户的情况下,它显示了此例外。我尝试了以不同的方式。我没有使用我的成功完整帐户ID作为硬编码)

0 个答案:

没有答案