Google登录错误:状态码:SIGN_IN_REQUIRED在Android上使用Google进行登录时 [英] Google Sign In error: Status Code: SIGN_IN_REQUIRED when signing in with Google on android

查看:6829
本文介绍了Google登录错误:状态码:SIGN_IN_REQUIRED在Android上使用Google进行登录时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次尝试使用Google API登录时,都会收到以下错误消息。我的清单具有适当的权限,我也相应地创建了我的凭据。所以我不知道问题是什么。

  com.omer.notetoself D / NTS :: ConnectionResult {statusCode = SIGN_IN_REQUIRED,resolution = PendingIntent {3678d5c:android.os.BinderProxy@19bcbe30},message = null} 






  package com.omer.notetoself; 

导入android.app.Activity;
导入android.content.Intent;
导入android.content.IntentSender;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.View;
导入android.widget.Button;
导入android.widget.EditText;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Scope;
import com.google.android.gms.plus.Plus;


`公共类Activity_Login扩展Activity实现View.OnClickListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {`


private static final int RC_SIGN_IN = 0;
私有GoogleApiClient mGoogleApiClient;
/ *是否有ConnectionResult解决方案正在进行中? * /
private boolean mIsResolving = false;

/ *我们是否应该尽可能自动解决ConnectionResults? * /
private boolean mShouldResolve = false;


EditText editText_userName;
EditText editText_password;

按钮button_facebook_login;
按钮button_google_login;
按钮button_login;
按钮button_signUp;

字符串userName;
字符串密码;

@Override
protected void onStop(){
super.onStop();
mGoogleApiClient.disconnect();


@Override
protected void onStart(){
super.onStart();
mGoogleApiClient.connect();
}

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

editText_userName =(EditText)findViewById(R.id.editText_username);
editText_password =(EditText)findViewById(R.id.editText_password);
button_login =(Button)findViewById(R.id.button_login);
button_facebook_login =(Button)findViewById(R.id.button_facebook);
button_google_login =(Button)findViewById(R.id.button_google);

button_signUp =(Button)findViewById(R.id.button_signup);
button_login.setOnClickListener(this);
button_signUp.setOnClickListener(this);
button_facebook_login.setOnClickListener(this);
button_google_login.setOnClickListener(this);


// GOOGLE + API

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this )
.addApi(Plus.API)
.addScope(新范围(Scopes.PROFILE))
.addScope(新范围(Scopes.EMAIL))
.build() ;
}


@Override
public boolean onCreateOptionsMenu(菜单菜单){
//使菜单膨胀;这会将项目添加到操作栏(如果存在)。
getMenuInflater()。inflate(R.menu.menu_activity_login,menu);
返回true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
// Handle action bar item clicks here here。操作栏将
//自动处理Home / Up按钮的点击,只要在AndroidManifest.xml中指定一个父活动,就可以获得长
的值。
int id = item.getItemId();

// noinspection SimplifiableIfStatement
if(id == R.id.action_settings){
return true;
}

返回super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v){
switch(v.getId()){
case R.id.button_login :// AUTHENTICATE PARSE
userName = editText_userName.getText()。toString()。trim();
password = editText_password.getText()。toString()。trim();
AppUtilities.parseLogin(this,userName,password);
休息;
case R.id.button_signup:// LAUNCH注册活动
Intent intent = new Intent(
Activity_Login.this,
Activity_SignUp.class);
startActivity(intent);
休息;
案例R.id.button_facebook:

AppUtilities.facebookLogin(this);
休息;
案例R.id.button_google:
initGoogle();



中断;




$ public void init(){
mGoogleApiClient.connect();
}

@Override
public void onConnected(Bundle bundle){
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
AppUtilities.googleLogin(this,email);
}

@Override
public void onConnectionSuspended(int i){

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult){
AppUtilities.log(connectionResult.toString());


if(!mIsResolving& mShouldResolve){
if(connectionResult.hasResolution()){
try {
connectionResult.startResolutionForResult(这个,RC_SIGN_IN);
mIsResolving = true;
} catch(IntentSender.SendIntentException e){
Log.e(AppUtilities.TAG,Could not resolve ConnectionResult。,e);
mIsResolving = false;
mGoogleApiClient.connect();
}
} else {
//无法解析连接结果,向用户显示
//错误对话框。
// showErrorDialog(connectionResult);
}
} else {
//显示退出的用户界面
// showSignedOutUI();




解决方案

确保您的应用程序在Google开发人员控制台中的SHA-1签名证书指纹属于您用于对您正在测试的APK进行签名的相同密钥。

默认情况下,汇编调试时,Android Studio使用自己的调试密钥。您可以通过右键单击应用程序并选择打开模块设置来更改它。转到签名选项卡并配置您在开发控制台中提到的相同密钥。之后,导航到构建类型选项卡并选择您的签名配置。


Everytime I try to login with Google API, I get the following error. My manifest has the appropriate permissions and I did create my credentials accordingly. So I don't know what the problem is. The consent screen doesn't show either.

com.omer.notetoself D/NTS:﹕ ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{3678d5c: android.os.BinderProxy@19bcbe30}, message=null}


  package com.omer.notetoself;

    import android.app.Activity;
    import android.content.Intent;
    import android.content.IntentSender;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    import com.google.android.gms.common.ConnectionResult;
    import com.google.android.gms.common.Scopes;
    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.common.api.Scope;
    import com.google.android.gms.plus.Plus;


     `public class Activity_Login extends Activity implements View.OnClickListener,GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener{` 


    private static final int RC_SIGN_IN = 0;
    private GoogleApiClient mGoogleApiClient;
    /* Is there a ConnectionResult resolution in progress? */
    private boolean mIsResolving = false;

    /* Should we automatically resolve ConnectionResults when possible? */
    private boolean mShouldResolve = false;


    EditText editText_userName;
    EditText editText_password;

    Button button_facebook_login;
    Button button_google_login;
    Button button_login;
    Button button_signUp;

    String userName;
    String password;

    @Override
    protected void onStop() {
        super.onStop();
        mGoogleApiClient.disconnect();
    }

    @Override
    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

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

        editText_userName = (EditText)findViewById(R.id.editText_username);
        editText_password = (EditText)findViewById(R.id.editText_password);
        button_login = (Button)findViewById(R.id.button_login);
        button_facebook_login = (Button)findViewById(R.id.button_facebook);
        button_google_login = (Button)findViewById(R.id.button_google);

        button_signUp = (Button)findViewById(R.id.button_signup);
        button_login.setOnClickListener(this);
        button_signUp.setOnClickListener(this);
        button_facebook_login.setOnClickListener(this);
        button_google_login.setOnClickListener(this);


        //GOOGLE+ API

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API)
                .addScope(new Scope(Scopes.PROFILE))
                .addScope(new Scope(Scopes.EMAIL))
                .build();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_activity_login, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.button_login: //AUTHENTICATE PARSE
                userName = editText_userName.getText().toString().trim();
                password = editText_password.getText().toString().trim();
                AppUtilities.parseLogin(this, userName, password);
                break;
            case R.id.button_signup: //LAUNCH SIGN UP ACTIVITY
                Intent intent = new Intent(
                        Activity_Login.this,
                        Activity_SignUp.class);
                startActivity(intent);
                break;
            case R.id.button_facebook:

                AppUtilities.facebookLogin(this);
                break;
            case R.id.button_google:
                initGoogle();



                break;

        }

    }

    public void initGoogle(){
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnected(Bundle bundle) {
        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
        AppUtilities.googleLogin(this,email);
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        AppUtilities.log(connectionResult.toString());


        if (!mIsResolving && mShouldResolve) {
            if (connectionResult.hasResolution()) {
                try {
                    connectionResult.startResolutionForResult(this, RC_SIGN_IN);
                    mIsResolving = true;
                } catch (IntentSender.SendIntentException e) {
                    Log.e(AppUtilities.TAG, "Could not resolve ConnectionResult.", e);
                    mIsResolving = false;
                    mGoogleApiClient.connect();
                }
            } else {
                // Could not resolve the connection result, show the user an
                // error dialog.
                //showErrorDialog(connectionResult);
            }
        } else {
            // Show the signed-out UI
            //showSignedOutUI();
        }
    }
}

解决方案

Make sure SHA-1 signing-certificate fingerprint of your app in google developers console belong to the same key which is used to sign APK you are testing.

By default, when assembling debug build Android Studio use own debug key. You can change it through right-clicking on the app and selecting "Open Module Settings". Go to "Signing" tab and configure the same key you have mentioned in dev console. After that navigate to the "Build Types" tab and select your signing configuration.

这篇关于Google登录错误:状态码:SIGN_IN_REQUIRED在Android上使用Google进行登录时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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