【问题标题】:Strange error while integrating Google plus集成 Google plus 时出现奇怪的错误
【发布时间】:2014-06-13 07:47:33
【问题描述】:

我正在通过此 URL https://developers.google.com/+/mobile/android/sign-in 在我的应用程序中集成 google plus,但我无法选择 google plus 帐户登录,并且在 ConnectionResult 中我总是得到 ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=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();
        }
    }
}

【问题讨论】:

    标签: android google-plus


    【解决方案1】:

    你没有在你的 OnClickListener 中做任何事情。

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

    【讨论】:

    • 不工作.. 同样的结果即将到来 ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4223c668: android.os.BinderProxy@4224b9c0}}
    猜你喜欢
    • 1970-01-01
    • 2013-06-19
    • 2013-03-26
    • 2016-09-06
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    相关资源
    最近更新 更多