【发布时间】:2013-12-28 21:41:05
【问题描述】:
我在使用 Google Drive Android SDK 时遇到了一个非常奇怪的问题。我已经使用它几个月了,直到上周它表现完美。但是,现在出现了一个非常奇怪的错误,它并非一直发生,而是 10 次中有 9 次发生。
我正在尝试列出存储在特定 Google Drive 文件夹中的用户文件和文件夹。当我尝试使用 Drive.files().list().execute() 方法时,10 次中有 9 次实际上没有任何反应。该方法只是挂起,即使我离开它一个小时,它仍然在做......什么都没有。
我正在使用的代码如下 - 所有这些都在 AsyncTask 的 doInBackground 中运行。我检查了凭据 - 它们都很好,应用程序证书的 SHA1 哈希也是如此。不抛出异常。谷歌搜索一无所获。这是困扰我的特定代码:
try {
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
SettingsActivity.this, Arrays.asList(DriveScopes.DRIVE));
if (googleAccountName != null && googleAccountName.length() > 0) {
credential.setSelectedAccountName(googleAccountName);
Drive service = new Drive.Builder(AndroidHttp.newCompatibleTransport(),
new GsonFactory(), credential).build();
service.files().list().execute(); // Google Drive fails here
} else {
// ...
}
} catch (final UserRecoverableAuthIOException e) {
// Authorisation Needed
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
startActivityForResult(e.getIntent(), REQUEST_AUTHORISE_GDRIVE);
} catch (Exception e) {
Log.e("SettingsActivity: Google Drive", "Unable to add Google Drive account due to Exception after trying to show the Google Drive authroise request intent, as the UserRecoverableIOException was originally thrown. Error message:\n" + e.getMessage());
}
}
});
Log.d("SettingsActivity: Google Drive", "UserRecoverableAuthIOException when trying to add Google Drive account. This is normal if this is the first time the user has tried to use Google Drive. Error message:\n" + e.getMessage());
return;
} catch (Exception e) {
Log.e("SettingsActivity: Google Drive", "Unable to add Google Drive account. Error message:\n" + e.getMessage());
return;
}
我正在使用 Drive API v2。谢谢大家!
编辑
玩了多一点,事实证明这不仅仅是为了列出文件。尝试与 Google Drive 上的任何文件进行交互的行为方式相同 - 删除、下载、创建......任何东西!我还注意到,将设备置于飞行模式以使其无法访问互联网也没有什么区别:Google Drive 不会抛出异常,甚至不会返回,它只会冻结它所在的线程。
我已更新到最新的 Drive API 库,但这并没有帮助。我记得在我将 JSch SSH 库添加到项目后不久就发生了错误,所以我删除了它,但没有任何区别。删除和重新添加 Drive API v2 也没有任何区别,清理项目也没有。
编辑 2
我发现了一些可能很重要的东西。在 Google Developer 控制台上,我记录了一些 Drive 错误,如下所示:
TOP ERRORS:
Requests % Requests Methods Error codes
18 38.30% drive.files.list 400
14 29.79% drive.files.insert 500
11 23.40% drive.files.update 500
4 8.51% drive.files.get 400
您认为这些是错误吗?我该如何修复它们?谢谢
【问题讨论】:
标签: java android google-drive-api