gpt4 book ai didi

android - 当 'Use another account' 登录时,谷歌登录不返回任何结果

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:50 25 4
gpt4 key购买 nike

这似乎是一项基本功能,但在遵循 signing-in tutorial 之后, 它只有在我选择已在设备上注册的帐户时才有效。

在选择“使用另一个帐户”并完成一些验证步骤后,它会丢失回调结果,(onActivityResult 未调用 ).

我使用 GoogleSignInOptions:没有发生异常,我无法添加任何监听器来检测异常。

但是,GoogleApiClient 工作正常,但有一些已弃用的方法,因此我决定切换到 GoogleSignInOptions 以避免弃用问题。
初始化:

googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);

点击时:

signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});

private void signIn() {
googleSignInClient.signOut();
Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 123);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 123 && data != null) {
handleSignInResult(data);
}
}

private void handleSignInResult(Intent data) {
Task<GoogleSignInAccount> signInTask = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount googleSignInAccount = signInTask.getResult(ApiException.class);
if (googleSignInAccount != null) {
updateUI(googleSignInAccount);
}
} catch (ApiException e) {
e.printStackTrace();
}
}

enter image description here


有人可以帮忙吗?

最佳答案

更新:此错误现已在 Oauth2 库中修复


所以我也遇到了同样的问题。我发现这是一个 open issue 3月份回来报道。所以这可能不是您的代码的问题。

我发现了另一个关于 difference between Oauth2 and googleAuthUtil 的 stackoverflow 问题,使用提到的其他库,我发现这个错误不存在。

我将这个包导入到我的gradle中

implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}

并通过 GoogleAccountCredential 对象进行身份验证。

    GoogleAccountCredential credential = new GoogleAccountCredential(context, scope);
startActivityForResult(credential.newChooseAccountIntent(), resultCode);

您需要GET_ACCOUNTS 权限才能使用此方法。

关于android - 当 'Use another account' 登录时,谷歌登录不返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50114176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com