无法使用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:

查看:193
本文介绍了无法使用Google Plus登录,并出现com.google.android.gms.common.api.ApiException:10:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Firebase登录Google plus并出现以下错误:

I am trying to login with Google plus using Firebase and getting below error:

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

我引用了 https://firebase.google.com/docs/auth /android/google-signin

这是我的下面的代码:

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);
    }
}
}

这是我下面的app.gradle:

Here is my app.gradle below:

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'

我还从Firebase导入了有效的google-services.json文件.但是不明白我要去哪里错了.

I have also imported valid google-services.json file from Firebase. But don't understand where I am going wrong.

先谢谢了!

推荐答案

错误的状态代码表示您正在提供未知的服务器客户端ID. 请使用下面的链接检查您的ID. https://console.developers.google.com/apis/credentials 在您的项目中,您可能需要生成: OAuth客户端ID-> Web应用程序,然后在您的Android应用中使用此Web应用程序客户端ID.

The status code which you got error means that you are providing unknown server client id. Please checked your id using below link. 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.

希望它可以帮助您解决问题.如果您使用此方法解决了问题,请以upvote结束您的问题.

Hope it helps you and solved your problem.If your problem solved using this then please closed your question with upvote.

这篇关于无法使用Google Plus登录,并出现com.google.android.gms.common.api.ApiException:10:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆