【发布时间】:2015-01-18 11:51:58
【问题描述】:
我尝试在 Android 上使用 API Google Drive,首先使用演示:
https://github.com/googledrive/android-quickstart
但是,我遇到了无法解决的错误。
GoogleApiClient 连接失败: ConnectionResult{statusCode=SIGN_IN_REQUIRED, 分辨率=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;
}
}
【问题讨论】:
-
在我的情况下,这个错误是由于应用程序包的某些内容与凭据中的内容不匹配造成的。需要确保包名称和 SHA1 必须匹配。在开发机器上运行的调试版本可能与发布版本具有不同的包名称和 SHA1。