【发布时间】:2017-09-21 22:15:40
【问题描述】:
我正在尝试在我的 Android 应用中实现 Google Drive,但我什至无法连接到 Api 客户端。我不知道为什么:
- 我已在开发者控制台中为 ~/.android/debug.keystore 配置项目和凭据(值似乎正确)
- 我从Drive for Android Documentation 复制粘贴了代码 -> 在方法
onConnectionFailed()中,如果connectionResult.hasResolution(),我将调用connectionResult.startResolutionForResult() - 在
onActivityResult中匹配requestCode我收到resultCode == 0(RESULT_CANCELLED) 即使我选择了我的帐户
你知道为什么吗?我也尝试添加:
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="----"/>
进入文档页面上未提及但在某些 SO 帖子中提及的清单。
感谢您的帮助
编辑:
我也尝试过使用enableAutoManage
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.build();
而不是手动配置连接和 connectionFailed 回调:
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
它在 onConnectionFailed 方法中返回错误代码 13。基于documentation,这似乎在以下情况下返回:
OnConnectionFailedListener 传递给 enableAutoManage(FragmentActivity, GoogleApiClient.OnConnectionFailedListener) 当用户选择不 完成提供的解决方案。例如通过取消对话框。
但我没有取消它。
我正在 Nexus 5x - Android N 上测试它
【问题讨论】: