简体   繁体   English

无法使用 Google Plus 登录,出现 com.google.android.gms.common.api.ApiException: 10:

[英]Unable to login using Google Plus, getting com.google.android.gms.common.api.ApiException: 10:

I am trying to login with Google plus using Firebase and getting below error:我正在尝试使用 Firebase 登录 Google plus 并收到以下错误:

com.google.android.gms.common.api.ApiException: 10: 

I refereed https://firebase.google.com/docs/auth/android/google-signin我推荐了https://firebase.google.com/docs/auth/android/google-signin

Here is my code below:这是我的代码如下:

package com.example.stackoverflow;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;

public class Main2Activity extends AppCompatActivity {
private static final int RC_SIGN_IN = 111;
GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signIn();
        }
    });

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}

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);
        String name = account.getDisplayName();
        String email = account.getEmail();
        Toast.makeText(this, "name: "+name+", email: "+email, Toast.LENGTH_LONG).show();
        Log.d("NIKHIL","name: "+name+", email: "+email);
        // Signed in successfully, show authenticated UI.
        //updateUI(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("NIKHIL", "signInResult:failed code=" + e.getStatusCode());
        //updateUI(null);
    }
}
}

Here is my app.gradle below:下面是我的 app.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.stackoverflow"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.github.barteksc:android-pdf-viewer:2.0.3'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.android.gms:play-services-auth:11.8.0'
}
apply plugin: 'com.google.gms.google-services'

I have also imported valid google-services.json file from Firebase.我还从 Firebase 导入了有效的google-services.json文件。 But don't understand where I am going wrong.但不明白我哪里出错了。

Thanks in Advance!!提前致谢!!

The status code which you got error means that you are providing unknown server client id.您收到错误的状态代码意味着您提供了未知的服务器客户端 ID。 Please checked your id using below link.请使用以下链接检查您的 ID。 https://console.developers.google.com/apis/credentials in your project you might need to generate: OAuth client ID -> Web Application and use this web application client id in your Android app. https://console.developers.google.com/apis/credentials在您的项目中您可能需要生成:OAuth 客户端 ID -> Web 应用程序并在您的 Android 应用程序中使用此 Web 应用程序客户端 ID。

Hope it helps you and solved your problem.If your problem solved using this then please closed your question with upvote.希望它对您有所帮助并解决了您的问题。如果您的问题使用此解决了,请通过投票结束您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.google.android.gms.common.api.ApiException: 10 - com.google.android.gms.common.api.ApiException: 10 com.google.android.gms.common.api.ApiException: 10: - com.google.android.gms.common.api.ApiException: 10: 异常com.google.android.gms.common.api.ApiException:12500 - Exception com.google.android.gms.common.api.ApiException: 12500 com.google.android.gms.common.api.ApiException: 12500 - com.google.android.gms.common.api.ApiException: 12500 安全网:com.google.android.gms.common.api.ApiException:16: - SAFETYNET : com.google.android.gms.common.api.ApiException: 16: com.google.android.gms.common.api.ApiException: 16: - com.google.android.gms.common.api.ApiException: 16: com.google.android.gms.common.api.ApiException:8: - com.google.android.gms.common.api.ApiException: 8: 谷歌登录失败 com.google.android.gms.common.api.ApiException: 10: - Google sign in failed com.google.android.gms.common.api.ApiException: 10: Google Play 服务游戏无提示登录错误 &#39;com.google.android.gms.common.api.ApiException: 4:&#39; - Google play service game Silent Login error 'com.google.android.gms.common.api.ApiException: 4: ' com.google.android.gms.common.api.ApiException: 10: 调用者未列入白名单以调用此 API - com.google.android.gms.common.api.ApiException: 10: Caller not whitelisted to call this API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM