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

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

问题描述

每次我尝试使用 Google API 登录时,都会收到以下错误.我的清单具有适当的权限,并且我确实相应地创建了我的凭据.所以我不知道问题是什么.同意屏幕也不显示.

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

推荐答案

确保您的应用在 google 开发者控制台中的 SHA-1 签名证书指纹属于用于签署您正在测试的 APK 的同一密钥.

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.

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

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 登录错误:在 Android 上使用 Google 登录时状态代码:SIGN_IN_REQUIRED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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