我正在设置GoogleSignInOptions和Google Api Client
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_ID))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Plus.API)
.build();
和我的谷歌网络应用程序客户端ID像这样:
1020847812450-xxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
但总是在onActivityResult
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
是假的
我在哪里做错了:S
onStart部分
mGoogleApiClient.connect();
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.d(TAG, "Got cached sign-in");
// GoogleSignInResult result = opr.get();
// handleSignInResult(result);
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
handleSignInResult(googleSignInResult);
}
});
}
onStop部分
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
onHandleSignInResult
private void handleSignInResult(GoogleSignInResult result) {
Log.e(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
final GoogleSignInAccount acct = result.getSignInAccount();
Log.e(TAG, acct.getDisplayName());
}
}
我也面临同样的问题。首先删除当前的OAuth客户端ID,之后再创建一个OAuth客户端ID。它对我有用。
你收到错误12501吗?我也有这个问题,因为我使用的是随SDK附带的debug.keystore
(由于某些原因我不知道,它不起作用)。我自己创建了一个新的,从它获得SHA-1哈希,在Google API控制台中输入然后它工作。
一定要设置signing configs for both debug and release builds with the new keystore。
按照所有步骤!! ..
发布APK和调试APK具有不同的SHA1和谷歌服务的不同API密钥。必须在Firebase控制台 - >项目设置中添加它们。然后从这里下载google-services.json,将其添加到项目中,并使用“Build signed APK”选项使用release keystore重新编译。这应该工作
并仔细阅读......
我相信你需要根据文件client.connect();
调用example:
GoogleApiClient client = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.setAccountName("[email protected]")
.build();
client.connect();
或者你的问题是否遗漏了,你在代码中的其他地方调用了qazxsw opi?