Google+ API始终会在应用开始时获取我的个人资料信息,并且无法清除帐户信息

时间:2014-09-12 06:28:53

标签: android google-api google-plus

我开始在我的应用上添加Google+ API,但奇怪的是它总是会收到我的个人资料信息,即使我还没有点击我的按钮在第二次运行时登录。我只是按照here步骤进行实施。到目前为止,这是我的代码:

在创建时我设置了我的ApiClient:

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();

然后我在onStart上有这个代码我希望它清除登录的最后一个帐户,然后是mGoogleApiClient.connect(); resolveSignInError()需要part,我不确定原因:

protected void onStart() {
        super.onStart();
        if (mGoogleApiClient.isConnected()) {
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
            mGoogleApiClient.disconnect();
        }
        mGoogleApiClient.connect();
    }

对于我的按钮点击监听器,我有这段代码开始注册:

public void SignupWithGoogle(View view) {

        social_login = 0;
        if(GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getBaseContext())==null){
                Toast.makeText(getBaseContext(), "Google Play services not available", Toast.LENGTH_SHORT).show();
        }else {
            //TODO Connect using google plus
            if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                mSignInClicked = true;
                resolveSignInError();
                progressDialog.setMessage("Logging In");
                progressDialog.show();
            }

            if (mGoogleApiClient.isConnected()) {
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                mGoogleApiClient.disconnect();
                mGoogleApiClient.connect();
                Toast.makeText(getBaseContext(), "Logged Out", Toast.LENGTH_SHORT).show();
            }
        }
    }

onStop我也试图断开用户的连接:

protected void onStop() {
        super.onStop();

        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }

    }

另一部分与给出的教程以及集成部分相同。我获得了onConnected后显示的用户凭据:

@Override
    public void onConnected(Bundle bundle) {
        // We've resolved any connection errors.  mGoogleApiClient can be used to
        // access Google APIs on behalf of the user.
        mSignInClicked = false;

        if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
            String gplus_email = Plus.AccountApi.getAccountName(mGoogleApiClient);

            if (gplus_email.length() > 0) {
                email.setText(gplus_email);
            } else {
                Toast.makeText(getBaseContext(), "No email found. Please specify your email", Toast.LENGTH_SHORT).show();
            }

        }


    }

现在我点击Google+按钮后会收到凭据,但问题出在我关闭应用程序之后又发现电子邮件还在那里,除非我再次点击Google+按钮,否则它不应该存在。我不知道我在哪里错过了,但我希望有人能帮助我。

1 个答案:

答案 0 :(得分:0)

您是否尝试撤消访问令牌并断开应用程序?

// Prior to disconnecting, run clearDefaultAccount().
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient)
    .setResultCallback(new ResultCallback<Status>() {

  onResult(Status status) {
    // mGoogleApiClient is now disconnected and access has been revoked.
    // Trigger app logic to comply with the developer policies
  }

})