Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

FB.IsLoggedIn always true after login once.

Discussion in 'Scripting' started by demozbox, Aug 2, 2022.

  1. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    Hello. I implemented login with facebook sdk.
    On my app start I check if the. user is logged in with

    if (FB.IsLoggedIn)

    But the issue is when you login once it returns true if you delete app from facebook settings. It returns false if you logout in app so it doesnt support multidevice gaming.
    How can I determine if my app was deleted from fasebook settings/linked apps ?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    FB is sorta weirdly tied in with operating systems on mobile... check the docs for that method and see what it is actually supposed to return. It might actually be functioning correctly.
     
  3. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    How can I check if the app was deleted from Facebook settings then?
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    If you mean when you go on Facebook and remove the permissions granted to the app, this should start to return false after. It always has for me. This forces a reprompt in the app to allow the permissions again, along with login.
     
  5. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    What commant should return?
    Even if I delete app on Facebook (not remove permissions), my app thinks it is olinked Facebook.
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    When a user logs in to your game using Facebook, they grant permissions to your game to use certain bits of info. Unless they go in and delete those permissions allow them to stay logged in for easy reloading of your app.

    Some conditions like token expiration, Facebook banning your game, etc where that would disable the permissions.

    As far as deleting the app from Facebook. If you mean going into Facebook developer portal and choosing to remove app, I notice this message when I try to do so.

    upload_2022-8-2_14-55-30.png

    Which suggest that the access tokens would be invalid, and IsLoggedIn should return false again.

    However, if this is not the behavior you are observing, you probably need to ask on the Facebook forums, as this is something with how their access tokens are setup.
     
  7. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    Nope. Any player can go to facebook/settings and privacy/settings/apps and websites
    There will be a list of apps where he was logged in. User can delete those apps links to his account.
    So, as developer of an app I want to know if I need to show login button unpressed in my game, but all the tutorials suggest to use FB.IsLoggedIn which is always true after first login.
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Yes, that is the removing permission section. Removing the app essentially removes all permissions, including the access token. After, IsLoggedIn should return false and allow you to reprompt. That has always been my experience with the Facebook login. I have added Facebook login to several games now, and have always had it behave that way.

    Are you using the latest FB unity sdk? Maybe the one you have is bugged. Also, how is your code setup?
     
  9. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    I've tried sdk 11 something and 13.2
    Same result- true whatever after first login.
     
  10. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Only thing I can say is maybe make sure you're removing the correct title and it's not a test version of the game on Facebook or something along those lines. It should still return false in the editor, but that gives a slightly odd behavior anyways, since it uses a test access token, so make sure you're getting true/false on a device as well.

    Unfortunately, I can only tell you that the proper behavior does happen and the check is for IsLoggedIn is the correct path to go.

    If you're still stuck, you can post the login code snippet and I can just verify if it matches what I've done in the past. Otherwise, it might be necessary to try the FB developer forums if nothing else comes to up.

    Also, I'm assuming that when you log in the first time with FB, you do get FB's login dialog and logging in with a real account? You can also try using test accounts that you can create on Facebook's developer portal and see if it behaves the same way.
     
  11. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    The code is very basic

    Code (CSharp):
    1. private void Init()
    2.     {
    3.         if (!FB.IsInitialized)
    4.             FB.Init(InitCallback, OnHideUnity);
    5.         else
    6.             ActivateApp();
    7.     }
    8.  
    9.     private void InitCallback()
    10.     {
    11.         Debug.LogWarning($"[FacebookServicesPm] check FB.IsInitialized on init {FB.IsInitialized}");
    12.  
    13.         if (FB.IsInitialized)
    14.             ActivateApp();
    15.     }
    16.  
    17.     private void ActivateApp()
    18.     {
    19.         FB.ActivateApp();
    20.         AuthCheckAfterDelay(1).DoAsync();
    21.     }
    22.  
    23.     private async Task AuthCheckAfterDelay(float delaySeconds)
    24.     {
    25.         await Task.Delay((int) (delaySeconds * 1000));
    26.  
    27.         var isLoggedInPlugin = FB.IsLoggedIn;
    28.  
    29.         Debug.Log($"[FacebookServicesPm]  FB.IsLoggedIn = {isLoggedInPlugin}");
    30. }
    31.  
     
  12. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Hmm. Interesting.

    Code (CSharp):
    1.     public void FBLogin()
    2.     {
    3.         if (!FB.IsInitialized)
    4.             FB.Init(OnInitComplete, OnHideUnity);
    5.         else
    6.             OnInitComplete();
    7.  
    8.     }
    9.  
    10.     private void OnInitComplete()
    11.     {
    12.         FB.ActivateApp();
    13.  
    14.         if (FB.IsLoggedIn)
    15.         {
    16.             OnLoggedIn();
    17.         }
    18.         else
    19.         {
    20.             FB.LogInWithReadPermissions(new List<string>() { "public_profile", "email", "user_friends" }, this.LoginCallback);
    21.         }
    22.     }
    This is the code I've used in apps I've worked on. Overall, similar and I don't see that a delay should change what FB.IsLoggedIn returns, unless for some reason that delay let's FB do something that logs them back in. But that seems weird.
     
  13. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    it is definitely doesn't login it back because I also check status on facebook settings and the app not linked in the list.
    So just weird.
    I will try with no delay, just in case.
     
  14. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    I've tried to remove delay and it changed nothing.
     
  15. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    At this point, I couldn't tell you. I know the isLoggedIn is the proper check.
    It even says so in FB docs
    https://developers.facebook.com/docs/unity/reference/current/Properties#IsLoggedIn

    You can read the bottom though about the best practices, but even there is still shows the code for the flow.

    But, if you are still getting it returning true, I would say, make sure your FB id is correct within Unity. Do the test on mobile and editor to see if the behavior matches. Try another user account (test users you can create on FB) to see if behavior is the same. Try creating a test version of your app on FB, which should have a different FB ID and try hooking into that.

    If all else fails, the FB forums. This doesn't appear to be a Unity related bug, since it's whatever FB is returning, so hopefully they could offer better help.