Android 谷歌+;API总是在应用程序启动时获取我的配置文件信息,并且可以';无法清除帐户信息
我开始在我的应用程序中添加Google+API,但奇怪的是,它总是能获取我的个人资料信息,即使我在第二次运行时还没有点击登录按钮。我只是按照实施的步骤。这是我到目前为止的代码: 在创建时,我设置我的ApicClient:Android 谷歌+;API总是在应用程序启动时获取我的配置文件信息,并且可以';无法清除帐户信息,android,google-api,google-plus,Android,Google Api,Google Plus,我开始在我的应用程序中添加Google+API,但奇怪的是,它总是能获取我的个人资料信息,即使我在第二次运行时还没有点击登录按钮。我只是按照实施的步骤。这是我到目前为止的代码: 在创建时,我设置我的ApicClient: mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedLi
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
然后我的onStart上有这段代码,我希望它清除最后登录的帐户,然后清除mGoogleApiClient.connect();ResolveSignError()需要部分,我不确定原因:
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();
}
}
}
在桌面上,我还尝试断开用户的连接:
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
其他部分与给出的教程以及集成部分相同。我获取用户凭据,以便在连接后显示:
@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+按钮,否则它不应该出现。我不确定我错过了什么,但我希望有人能在这方面帮助我。你是否尝试取消访问令牌并断开应用程序的连接
// 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
}
})
//断开连接之前,请运行clearDefaultAccount()。
Plus.AccountApi.clearDefaultAccount(mgoogleapClient);
Plus.AccountApi.revokeAccessAndDisconnect(mgoogleAppClient)
.setResultCallback(新的ResultCallback(){
onResult(状态){
//mGoogleApiClient现在已断开连接,访问权限已被吊销。
//触发应用程序逻辑以符合开发人员策略
}
})