question

nikolalemmens avatar image
nikolalemmens asked

Facebook Login after link succeeded

Hi,

We let the player log in via device. Then after a few games he can link with FB.

As explained in the tutorial (https://api.playfab.com/docs/tutorials/landing-players/facebook-unity) linking the player works nicely:

public void LinkFacebook()
        {
            Debug.Log("Link Facebook");


            FB.Init(OnFacebookInitialized);
        }


        private void OnFacebookInitialized()
        {
            Debug.Log("Logging into Facebook");


            // We invoke basic login procedure and pass in the callback to process the result
            FB.LogInWithReadPermissions(null, OnFacebookLoggedIn);
        }


        private void OnFacebookLoggedIn(ILoginResult result)
        {
            // If result has no errors, it means we have authenticated in Facebook successfully
            if (result == null || string.IsNullOrEmpty(result.Error))
            {
                Debug.Log("Access Token: " + AccessToken.CurrentAccessToken.TokenString);
                ZPlayerPrefs.SetString(fbAccesKey, AccessToken.CurrentAccessToken.TokenString);


                LoginWithFacebookRequest request = new LoginWithFacebookRequest()
                {
                    CreateAccount = true,
                    AccessToken = AccessToken.CurrentAccessToken.TokenString,
                    InfoRequestParameters = accountParams
                };
                PlayFabClientAPI.LoginWithFacebook(request, OnLoggedIn, OnLoginError);
            }
            else
            {
                Debug.Log("Facebook Auth Failed: " + result.Error + "\n" + result.RawResult);
            }
        }

When the player logs in for a next game, we have the following Start method:

       void Start()
        {
            if (HasStoredLogin()) {
                LoginWithEmail(ZPlayerPrefs.GetString(emailKey), ZPlayerPrefs.GetString(pwdKey));
            } else if (HasFbAccesKey ()) {
                LoginWithFacebookRequest request = new LoginWithFacebookRequest() {
                    AccessToken = ZPlayerPrefs.GetString(fbAccesKey),
                    InfoRequestParameters = accountParams
                };
                PlayFabClientAPI.LoginWithFacebook(request, OnLoggedIn, error => {
                    OnLoginError(error);
                    instance.LoginWithDevice();
                });
            } else {
                LoginWithDevice();
            }
            #endif
        }

Although HasFbAccesKey returns true and the AccesToken (retrieved from the linking) is passed in the request, the LoginWithFacebook call returns an error and thus a LoginWithDevice is called (which isn't so bad).

But I fail to see why the LoginWithFacebook call doesn't succeed. What could be the issue?

10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

Once you've linked the player's Facebook account to their PlayFab account, that's specifically how the login call works - you should be able to call LoginWithFacbook with the Access Key for the player and have them sign in, no problem. In fact, that's exactly how other titles use the API call. How exactly are you getting the Access Token from Facebook in the client code? What Title ID are you using, and what's the PlayFab ID of a player account in your title where you have linked Facebook but can't use the login call?

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.

nikolalemmens avatar image nikolalemmens commented ·

Oops, forgot to pass in the Title ID in the request. Works perfect now, thx!!

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.