9

I have an android app and I'm implementing share following these instructions.

I manage to get it working. I came back to it the next day and I get this output in logcat:

 G+ on connection failed ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{422d8470: android.os.BinderProxy@422d8410}}

I have triple checked the api console, removed my OAuth clientID and input again fresh. This has not fixed it. Any idea about what I can look into to fix it?

4

1 回答 1

10

出于多种原因,您可以获得 SIGN_IN_REQUIRED 连接结果,例如:

  • 如果你打电话PlusClient.clearDefaultAccount();
  • 如果您在http://plus.google.com/apps上或调用PlusClient.revokeAccessAndDisconnect();.
  • 如果您的应用在之前请求的授权范围之外还请求授权范围。

对于 SIGN_IN_REQUIRED,您收到的 ConnectionResult 包含可用于解决问题的 PendingIntent。在您遵循示例代码的说明示例中,使用以下代码处理错误onConnectionFailed

@Override
public void onConnectionFailed(ConnectionResult result) {
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
        } catch (SendIntentException e) {
            mPlusClient.connect();
        }
    }
    // Save the result and resolve the connection failure upon a user click.
    mConnectionResult = result;
}

result.startResolutionForResult()将显示帐户选择器或权限对话框以解决上述问题,并将控制权返回给onActivityResult,例如:

@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
    if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
        mConnectionResult = null;
        mPlusClient.connect();
    }
}

此时调用PlusClient.connect()应该成功。

于 2013-05-28T12:03:07.720 回答