谷歌硬盘授权问题Android-com.Google.api.client.googleapis.extensions.Android.gms.auth.UserRecoverableAuthIOException
在我的应用程序中有两个文件,一个片段和一个活动。在片段的onResume()中,我调用活动进行授权谷歌硬盘授权问题Android-com.Google.api.client.googleapis.extensions.Android.gms.auth.UserRecoverableAuthIOException,android,google-drive-api,google-drive-android-api,Android,Google Drive Api,Google Drive Android Api,在我的应用程序中有两个文件,一个片段和一个活动。在片段的onResume()中,我调用活动进行授权 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initialize credentials and service object. SharedPreferences settings = getPreferences(Con
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();
}
在这个活动中,我将emailId保存在SharedReferences中。这是有效的
然后在侧面,我试图访问片段文件中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();
}
private void列表文件夹(最终字符串folderId,最终字符串emal)
抛出IOException{
mGOOSvc=new com.google.api.services.drive.drive.Builder(AndroidHttp.newCompatibleTransport(),new GsonFactory(),
GoogleAccountCredential.UsingAuth2(this.getActivity(),Collections.singletonList(DriveScopes.DRIVE))
.setSelectedAccountName(emal)
).build();
最终ArrayList al=新ArrayList();
最终ArrayList alIds=新ArrayList();
alIds.clear();
request=mGOOSvc.children().list(folderId);
新建异步任务(){
@凌驾
受保护的字符串doInBackground(字符串…参数){
做{
试一试{
ChildList children=request.execute();
for(ChildReference子项:children.getItems()){
字符串childId=child.getId();
File File=mGOOSvc.files().get(childId.execute();
如果(!file.getExplicitlyTrashed()&&file.getMimeType().equals(“application/vnd.google apps.folder”)){
al.add(file.getTitle());
add(file.getId());
}
}
request.setPageToken(children.getNextPageToken());
}捕获(例外e){
System.out.println(“发生错误:+e.getMessage());
request.setPageToken(null);
}
}while(request.getPageToken()!=null&&
request.getPageToken().length()>0);
返回null;
}
}.execute();
}
它在ChildList children=request.execute();)上显示异常:com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException
(它与我的一个GoogleDrive帐户完美配合。但对于其他帐户,它会显示此异常。我尝试了不同的方式。我没有使用我的成功完整帐户Id作为硬编码)我检查了Google Drive--设置--管理应用程序。只有一个google drive帐户在“管理应用”中列出了我的应用名称。该帐户已成功使用我的应用程序。我的假设是其他帐户没有正确连接到我的android应用程序。请问该应用程序何时将添加到此列表中。是在登录时间还是授权页面?当您的应用程序的用户选择新帐户,并且该用户通过授权屏幕说用户授予应用程序干扰其驱动器的权限时。见@seanpj谢谢。。。现在它的作品。但我有一个问题。在特殊账户情况下,一个应用程序的授权屏幕将只有一个?因为我在一台设备上安装了应用程序,当时显示了一个特定帐户的授权屏幕。我再次在另一台设备上安装了应用程序,并登录了同一个帐户。当时,此授权页面从未显示(但有效)。。在第一次登录时,是否可以向每个设备显示授权页面?我想(我不是最新的),只要有新的应用程序安装+新帐户,就会请求授权。因此,如果使用相同的帐户重新安装应用程序,则不会显示。不过,这其中有一个陷阱,如果你的用户过于勇敢,并且测试事情的运行方式(我认为Daniel是一位内幕人士),那么这可能会导致一场大混乱。你可以通过编程撤销授权吗?(类似于-设置>管理应用程序>断开与驱动器的连接)