Android Facebook SDK: Check if the user is logged in or not

后端 未结 10 1465
南旧
南旧 2020-12-04 12:43

I\'m have a feature on my Android app where the user authorizes the app and shares a link.

I also need to give an option for the user to logout of facebook and I nee

相关标签:
10条回答
  • 2020-12-04 13:11

    For Facebook Android SDK 4.x you have to use the "AccessToken.getCurrentAccessToken()" as said by @Diljeet but his check didn't work for me, I finally checked it by doing:

    Activity "onCreate":

    facebookAccessToken = AccessToken.getCurrentAccessToken();
    

    To check if the session is still active (I made it in the "onResume" method but do it where you need):

      if(facebookAccessToken != null){
            sessionExpired = facebookAccessToken.isExpired();
      }else{
            sessionExpired = true;
      }
    

    More info in https://developers.facebook.com/docs/facebook-login/android

    0 讨论(0)
  • 2020-12-04 13:16

    Note to readers: This is now deprecated in the new FB 3.0 SDK.

    facebook.isSessionValid() returns true if user is logged in, false if not.

    0 讨论(0)
  • 2020-12-04 13:19

    Android Studio with :

    compile 'com.facebook.android:facebook-android-sdk:4.0.1'
    

    then check login like as:

    private void facebookPost() {
        //check login
        AccessToken accessToken = AccessToken.getCurrentAccessToken();
        if (accessToken == null) {
            Log.d(TAG, ">>>" + "Signed Out");
        } else {
            Log.d(TAG, ">>>" + "Signed In");
        }
    }
    
    0 讨论(0)
  • 2020-12-04 13:20

    I was using FB sdk for just for login.. Facebook developers reject my app, Because whenever user login, I send logout.. I dont matter user profile data... I just use FB for login.. FB tells if user login... dont send lgout...

    I find Hacking way... Now my app doesnot send logout whenever user login.... Whatever user login with,Google,Facebook,or normal.. When they click logout... In this three condition I use LoginManager.getInstance().logOut();

    No matter which platform they use... There is no crash :)

    0 讨论(0)
提交回复
热议问题