首页 文章

整合Google plus时出现奇怪的错误

提问于
浏览
0

我整合谷歌加上从这个网址我的应用程序https://developers.google.com/+/mobile/android/sign-in但我不能够得到谷歌的选择器加上帐户登录,并在ConnectionResult我总是得到ConnectionResult {=的StatusCode SIGN_IN_REQUIRED,分辨率= {的PendingIntent 4223c668:android.os.BinderProxy @ 4224b9c0}} ...我尝试了很多链接,并创建并删除了客户端ID,它不适用于我这是我的代码

@Override
protected void onCreate(Bundle savedInstanceState) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
                    .addApi(Plus.API)
        .addScope(Plus.SCOPE_PLUS_LOGIN).build();

    btnGooglePlus = (SignInButton) findViewById(R.id.sign_in_button);
    btnGooglePlus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (v.getId() == R.id.sign_in_button
                    && !mGoogleApiClient.isConnecting()) {
                mSignInClicked = true;
            }
        }
    });


}

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

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode != RESULT_OK) {
            mSignInClicked = false;
        }

        mIntentInProgress = false;

        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    }
}

@Override
public void onConnectionFailed(ConnectionResult result) {

    if (!mIntentInProgress) {
        // Store the ConnectionResult so that we can use it later when the
        // user clicks
        // 'sign-in'.
        mConnectionResult = result;

        if (mSignInClicked) {
            // The user has already clicked 'sign-in' so we attempt to
            // resolve all
            // errors until the user is signed in, or they cancel.
            resolveSignInError();
        }
    }
}

@Override
public void onConnected(Bundle arg0) {
    Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
}

@Override
public void onConnectionSuspended(int cause) {
    mGoogleApiClient.connect();
}

/* A helper method to resolve the current ConnectionResult error. */
private void resolveSignInError() {
    if (mConnectionResult.hasResolution()) {
        try {


    mIntentInProgress = true;
            mConnectionResult.startResolutionForResult(this,       RC_SIGN_IN);

        } catch (SendIntentException e) {
            // The intent was canceled before it was sent. Return to the
            // default
            // state and attempt to connect to get an updated
            // ConnectionResult.
            mIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
}

1 回答

  • 1

    您在 OnClickListener 中没有做任何事情 .

    您需要从 onClick 调用 resolveSignInError() ,它将识别 SIGN_IN_REQUIRED 并相应地启动登录流程 .

相关问题