简体   繁体   中英

How i get, is user login or logout in facebook sdk 4.0.1

I am using Facebook new sdk 4.0.1, in that when i get log-in button changes to log-out and same button is used to logout without any code. but actually i want to do some coding at time of log-out. so how i get differentiate between these two things in that sdk? How i declare logout method ?

You could check when the token changes, and if the new access token is null, the user just logged out.

new AccessTokenTracker() {
    @Override
    protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
        if (newAccessToken==null)
            //your code here!
    }
};

Login Updates

Session Removed - AccessToken, LoginManager and CallbackManager classes supercede and replace functionality in the Session class.

Access Tokens - You can load AccessToken.getCurrentAccessToken with the SDK from cache or if the app is cold launched from an app bookmark. For instructions, see Facebook Login for Android, Get Current Token.

Login Button - The easiest way to add Login is to use the LoginButton in 4.x. See Facebook Login for Android, Add Facebook Login.

UserSettingsFragment class has been removed from the SDK.

LoginManager is a singleton instance, and works with the AccessToken's currentAccessToken. After login the SDK sets currentAccessToken. To get additional permissions call the logInWith... methods.

LogInWith... methods always open a prompt UI if necessary. There's no equivalent to the Session.openActiveSessionFromCache or Session.OpenActiveSession(Activity, boolean, StatusCallback). Instead, you should check AccessToken.getCurrentAccessToken() at onCreate(), and if not null, skip login.

AccessToken broadcast events when it is set, unset or updated. Use the AccessTokenTracker to receive these events. See Facebook Login for Android, Track Access Tokens.

currentAccessToken automatically caches when the SDK sets it.

ProfileTracker.getCurrentProfile returns the current logged in user.

ProfileTracker returns events if the logged in user changes. see Facebook Login for Android, Track Current Profile.

CallbackManager.onActivityResult replaces Session.onActivityResult and UiLifecycleHelper.onActivityResult. See Facebook Login for Android, Register a Callback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM