[英]Check if the user when log out from facebook in android facebook sdk 4
my problem is that I hav an app which can connects to facebook using facebook sdk new version(4.0) and I want that when the user logs into facebook , a textview appears and show it's name and when log out clicked the textview disappears . 我的问题是我拥有一个可以使用facebook sdk new version(4.0)连接到facebook的应用程序,我希望当用户登录到facebook时,出现一个textview并显示其名称,而单击退出时textview消失 。
the first part is done and I can get the data I want: 第一部分已经完成,我可以获得所需的数据:
btnLoginButton.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
fBLogInClicked = true;
GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object,
GraphResponse response) {
try {
String jsonresult = String
.valueOf(object);
String str_firstname = object .getString("first_name");
String str_lastname = object
.getString("last_name");
fullName = str_firstname + " "
+ str_lastname;
} catch (JSONException e) {
e.printStackTrace();
}
if (fullName != null) {
txtFBEmail
.setVisibility(View.VISIBLE);
txtFBEmail.setText(fullName);
}
}
}
}).executeAsync();
}
but after logout I don't know how to understand that logout is clicked and then to set visibility of txtFBEmail gone. 但是注销后,我不知道如何了解单击了注销,然后无法设置txtFBEmail的可见性。
I tryed this code on onCreate() but just when I restart the app is partly useful and when log out clicks I can not give the order to disappear the textview.: 我在onCreate()上尝试过此代码,但是仅当我重新启动应用程序时才有部分用处,并且在单击注销后,我无法下令消失textview。
AccessToken fb_token = AccessToken.getCurrentAccessToken();
if(fb_token == null) {
txtFBEmail.setVisibility(View.GONE);
}
this method would help you to do what ever you want the exact time that logout is clicked: 此方法将帮助您完成点击注销的确切时间:
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken,
AccessToken currentAccessToken) {
if (currentAccessToken == null) {
//write your code here what to do when user clicks on facebook logout
checkLoggedInProfile();
}
}
};
Use this code for facebook sdk 4. 将此代码用于facebook sdk 4。
profile = Profile.getCurrentProfile().getCurrentProfile(); if (profile != null) { // user has logged in txtFBEmail.setVisibility(View.visible); } else { // user has not logged in txtFBEmail.setVisibility(View.GONE); }
for more information about new facebook-sdk 4 integration you can check my answer here. 有关新的facebook-sdk 4集成的更多信息,您可以在此处查看我的答案。 Facebook Login with SDK4
使用SDK4登录Facebook
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.