gpt4 book ai didi

java - Google 登录仅适用于第一台设备

转载 作者:行者123 更新时间:2023-12-02 09:10:27 24 4
gpt4 key购买 nike

我在使用 Google 登录时遇到问题,因为第一个登录设备没有问题,但此后的任何设备都会出现“失败”消息。 log cat 中的错误仅显示“signInResult:failed code=10”,我搜索了此错误,找到的一些解决方案是确保 firebase 和 google 具有与我从签名报告中获得的相同的 SHA1 key 。

只是为了确保,我必须放置 SHA1 key 的 google 端是否正确? https://developers.google.com/identity/sign-in/android/start-integrating .

如果是这样,我已经这样做了,但问题仍然存在。

感谢任何帮助,谢谢

编辑:顺便说一句,这是处理 googlesignin 的代码,经过多次测试,它似乎只能在一台设备上运行,该设备随后收到一条失败消息。

public class SplashScreen extends AppCompatActivity {

int RC_SIGN_IN = 0;
GoogleSignInClient mGoogleSignInClient;
private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);


// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

signIn();

}

private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
startActivity(new Intent(SplashScreen.this, MainActivity.class));
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("Google Sign In Error", "signInResult:failed code=" + e.getStatusCode());
Toast.makeText(SplashScreen.this, "Failed", Toast.LENGTH_LONG).show();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Do something after 5s = 5000ms
finish();
System.exit(0);
}
}, 2000);
}
}

@Override
protected void onStart() {
// Check for existing Google Sign In account, if the user is already signed in
// the GoogleSignInAccount will be non-null.
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if(account != null) {
startActivity(new Intent(SplashScreen.this, MainActivity.class));
}
super.onStart();
} }

最佳答案

我解决了这个问题,结果发现我没有在 firebase 的身份验证选项卡中注册谷歌登录。我没有这样做的原因是我遵循的教程没有使用 firebase。我傻了。

编辑:此外,我使用了调试 SHA1 key (我认为是已发布的 key )而不是发布 key 。

关于java - Google 登录仅适用于第一台设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59463341/

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