gpt4 book ai didi

android - com.google.android.gms.common.api.ApiException : 12500

转载 作者:太空狗 更新时间:2023-10-29 15:40:03 24 4
gpt4 key购买 nike

这是我的第一次尝试....试图找出最近 2 天的问题。我正在尝试将 google 登录集成到 android 应用程序中,但是如下所示:com.google.android.gms.common.api.ApiException: 12500

遵循以下代码: https://firebase.google.com/docs/auth/android/google-signin

  • 确保开发控制台中存在 oauth 客户端 ID,并按照其他帖子中的建议使用来自 ~/.android/debug.keystore 的正确 SHA-1 指纹。

  • 在应用级别使用最新的播放服务 49 和 build.gradle:实现 'com.google.android.gms:play-services-auth:16.0.1'

  • 在项目级 build.gradle 中使用以下内容:

buildscript {//... dependencies {//... classpath 'com.google.gms:google-services:4.1.0'//google-services 插件 }

public class SignUpActivity extends AppCompatActivity {

private GoogleSignInClient gsc;

private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
GoogleSignInOptions gso = new GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(String.valueOf(R.string.gplus_api_client_id))
.requestEmail()
.build();

gsc = GoogleSignIn.getClient(this, gso);

//Initialize firebase authentication
firebaseAuth = FirebaseAuth.getInstance();
}


@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 {
//Sign in Successful
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
Log.w("SignUpActivity/handleSignInResult", "Trying signing in with Google... " + account);
firebaseAuthWithGoogle(account);

// Signed in successfully, show authenticated UI.

// Log.w("SignUpActivity/handleSignInResult", "Google sign in successful for account " + account);

} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("SignUpActivity/handleSignInResult", "Google sign in failed with exception: " + e);
}
}

private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
Log.i("SignUpActivity/firebaseAuthWithGoogle", "Signed in as : " + account.getId());

AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);

firebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
FirebaseUser user = firebaseAuth.getCurrentUser();
Log.i("SignUpActivity/firebaseAuthWithGoogle", "Sign in successful for user : " + user);
} else {
Log.e("SignUpActivity/firebaseAuthWithGoogle", "User Authentication failed.");
Snackbar.make(findViewById(R.id.view_signup), "Authentication failed.", Snackbar.LENGTH_SHORT);
}
}
});
}
}

最佳答案

我有这个问题。并且已经解决了。 SHA1 debug 和 relase 都已添加到 Firebase 控制台,但仍然无法正常工作。我也尝试只进行 SHA1 调试,但仍然没有用。经过这么多次尝试和错误后,我通过从凭据菜单中完成“oAuth 同意屏幕”的信息解决了它,步骤如下:

  1. 登录到 Google Console Cloud
  2. 选择与当前 Firebase 项目相关的当前项目
  3. 导航到 API 和服务
  4. 点击凭据菜单
  5. 点击“oAuth 同意屏幕”
  6. 添加应用程序 Logo 、应用程序主页链接和应用程序隐私政策链接。要添加这两个链接,您只需从“oAuth 同意屏幕”的授权域部分复制并粘贴,例如:your-app-abc123.firebaseapp.com

关于android - com.google.android.gms.common.api.ApiException : 12500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52785132/

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