我尝试在Android上使用API Google Drive,首先使用该演示:
https://github.com/googledrive/android-quickstart
但是,我有这个错误,我无法解决 .
GoogleApiClient连接失败:ConnectionResult {statusCode = SIGN_IN_REQUIRED,resolution = PendingIntent {421d40e8:android.os.BinderProxy@42137f78}}
@Override
public void onConnectionFailed(ConnectionResult result) {
// Called whenever the API client fails to connect.
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
return;
}
// The failure has a resolution. Resolve it.
// Called typically when the app is not yet authorized, and an
// authorization
// dialog is displayed to the user.
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (requestCode == REQUEST_CODE_RESOLUTION) {
if (resultCode == RESULT_OK) {
Log.i(TAG, "Error resolution success.");
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
} else {
GooglePlayServicesUtil.getErrorDialog(requestCode, this, 0).show();
}
break;
}
}
4 回答
这可能是由于开发人员的疏忽(因为它发生在我身上) - 您在控制台上提供的SHA1详细信息是 生产环境 密钥的详细信息,您正在调试模式下测试(SHA1详细信息会有所不同) . 但是,谷歌驱动器API的错误消息可能会更好!
Here是您收到的错误的信息 . 我假设您是,但您需要登录才能访问 Cloud 端硬盘 . 当我运行示例应用程序时,它一开始就要求我选择一个帐户 . 也许您没有与您使用的设备同步的帐户? "add account"有一个选项,但如果您的帐户为零,则行为可能不同 . 文档建议您继续不使用API(只是因为除非您登录才能继续)或调用
startResolutionForResult(Activity, int)
以提示用户登录,但最简单的可能是add the account to your device .你可以在这里引用我的答案https://stackoverflow.com/a/41658044/4448757来连接谷歌帐户,这只适用于签名的apk
然后你可以去谷歌驱动器
不确定是否有人仍然需要这个,但在我的情况下,我有两个谷歌帐户,所以我首先需要选择我想要使用的帐户 . 我在
onConnectionFailed
中使用了这段代码