“使用其他帐户"登录时,Google登录不会返回任何结果 [英] Google Sign in doesn't return any result when 'Use another account' to sign in
问题描述
这似乎是一项基本功能,但在遵循签名后,在教程中,仅当我选择设备上已注册的帐户时,该功能才有效.
This seems to be a basic feature but after following the signing-in tutorial, it only works if I choose the account that is already registered on the device.
选择"使用其他帐户"并完成一些步骤进行身份验证后,将会丢失回叫结果(onActivityResult
为未呼叫).
After choosing 'Use another account' and completing some steps to authenticate it looses the call-back result, (onActivityResult
is not called).
我使用GoogleSignInOptions
:没有异常发生,并且我无法添加任何侦听器来检测异常.
I use GoogleSignInOptions
: no exception occurs and I can't add any listener to detect exceptions.
但是,GoogleApiClient
可以正常工作,但是有一些不推荐使用的方法,因此我决定切换到GoogleSignInOptions
以避免出现不推荐使用的问题.
初始化:
However, GoogleApiClient
works fine but there are some deprecated methods, thus I decided to switch to GoogleSignInOptions
to avoid deprecation issues.
Initizlization:
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();
}
}
任何人都可以帮忙吗?
推荐答案
更新:此错误现已在Oauth2库中修复
UPDATE: This bug has now been fixed in the Oauth2 Library
所以我也遇到了同样的问题.我发现这是3月报告的未解决问题.因此,这可能与您的代码无关.
So I ran into the same issue as well. What I have found is that this is an open issue reported back in March. So this is probably not an issue with your code.
我发现了另一个有关 Oauth2与googleAuthUtil ,使用提到的另一个库,我发现此错误不存在.
I found another stackoverflow question about the difference between Oauth2 and googleAuthUtil, using the other library mentioned, I have found that this bug doesn't exist.
我将此软件包导入了我的gradle
I imported this package into my gradle
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
并从GoogleAccountCredential
对象进行身份验证.
and authenticate off of the GoogleAccountCredential
object.
GoogleAccountCredential credential = new GoogleAccountCredential(context, scope);
startActivityForResult(credential.newChooseAccountIntent(), resultCode);
此方法需要GET_ACCOUNTS
权限.
这篇关于“使用其他帐户"登录时,Google登录不会返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!