gpt4 book ai didi

java - 无法在 Android 应用程序中使用 Google 登录

转载 作者:行者123 更新时间:2023-12-04 07:40:33 24 4
gpt4 key购买 nike

我已经尝试了这里提到的许多解决方案,但我仍然无法解决这个问题。我收到:
“谷歌登录失败。com.google.android.gms.common.api.ApiException: 10”
我已经验证了我的 Google Cloud Console 中 OAuth 自动生成的“网络客户端 key ”相同 正如我在代码中使用的那样。但我遇到了同样的错误。我还验证了 Google Cloud Console 和 Firebase 中的项目名称相同。
这是我的代码:

public class LoginActivity extends Activity {

private GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private static final int RC_SIGN_IN = 1;
static LoginActivity loginActivity;
private FirebaseUser currentUser;

public static LoginActivity getInstance(){
return loginActivity;
}
public FirebaseUser getCurrentUser() {
return currentUser;
}

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

GoogleSignInOptions gso = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();

mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
mAuth = FirebaseAuth.getInstance();

View signInButton = findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
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 GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
//Here resultCode is 0 & requestCode is 1.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// This line of code is throwing exception.
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.w(TAG, task.getException());
Log.d(TAG, "firebaseAuthWithGoogle:" + account.getId());
firebaseAuthWithGoogle(account.getIdToken());
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
}
}
}
我正在关注 this来自官方文档的教程。任何帮助表示赞赏。
附言我也在同一个项目中使用 Firestore 数据库。我已经成功地将 google-services.json 保存在 中应用程序 文件夹。

最佳答案

关于java - 无法在 Android 应用程序中使用 Google 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67502180/

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