question

mormert avatar image
mormert asked

How to login once and then stay logged in to Facebook?

Hello, I am making a iOS & Android game where I want players to be able to login to Facebook once, but I don't want them to have to enter login information every time they play the game. Like a "Remember Me" function, and I wonder how can I do that?

I am new to PlayFab.

What is best practise? Thanks.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Facebook does not provide an infinite-use delegate token, since that would be a serious security risk to their customers. When you sign into Facebook, you provide a token which has a lifespan (it should be an hour or two, but Facebook's doc state that they may change that at any time, so it's important to check responses to see whether you need to "refresh" the token). So whenever you sign the player in, you'll need to request a fresh token from Facebook.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mormert avatar image
mormert answered

Thanks for super fast anwser @Brendan :)

I am using Unity by the way and this is the code that I use when players start the game...

if(LoginWithFacebook == true)
{
    if (!FB.IsInitialized)
    {
        FB.Init(OnFacebookInitialized);
    }
    else
    {
        if (!FB.IsLoggedIn)
        {
            Debug.Log("FB already initialized, only logging in...");
            FB.LogInWithReadPermissions(null, OnFacebookLoggedIn);
        }
        else
        {
            Debug.Log("Attempted to login, but you are already logged in!");
        }
    }
}

Should I really use FB.LogInWithReadPermissions every time the player starts the game? I feel a bit confused here, like there is something I have missed? - When I test this on my Android phone, the phone opens up Facebook for a short second or so, then logs in. But isnt there a way to solve that?

Or does every game really do this? I haven't really played games on Android, but Facebook-connected games on iOS does certainly not pop the FB-login dialog every time.

And how do I request a "fresh" token from Facebook?

Do you mean when I sign in the player to Facebook or something else, that I request the token?

Is there any guides that you can recommend for doing this? I haven't really found alot on google etc.

Sorry for my confusion here :-)

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Yes, in order to have the ability for PlayFab to make service calls on behalf of the player, we need to have an up-to-date user access token, so making the login call whenever you log the player into the game in our service would be the right thing to do.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.