How to check if user is logged in with FB SDK 4.0 for Android?

前端 未结 6 1754
走了就别回头了
走了就别回头了 2020-11-30 18:56

A few days ago I implemented FB Login to my APP, and today I found out that most of the things I have implemented are now deprecated.

Before, I was using Sess

6条回答
  •  渐次进展
    2020-11-30 19:00

    My dilemma of using AccessToken and AccessTokenTracker for checking login status is that when AccessToken is ready and callback function of the tracker called but profile may be not ready yet, thus I cannot get or display Facebooker's name at that moment.

    My solution is to check current profile != null and use its tracker for having Facebooker's name at the same time:

        ProfileTracker fbProfileTracker = new ProfileTracker() {
            @Override
            protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
                // User logged in or changed profile
            }
        };
    

    Check login status and then get user name:

    Profile profile = Profile.getCurrentProfile();
    if (profile != null) {
        Log.v(TAG, "Logged, user name=" + profile.getFirstName() + " " + profile.getLastName());
    }
    

提交回复
热议问题