question

aliceconnex@gmail.com avatar image
aliceconnex@gmail.com asked

Invalid Facebook Token

I'm using Facebook to create a new account in Playfab. I've already test the code where I use to connect the user with Facebook using User Access Token. However, when I use PlayFab to create a new user, I get this error.

"HTTP: 400

HTTP Status: BadRequest

Error Message: Invalid Facebook Token"

 



Here is my code which is used to create a new PlayFab Account using Facebook Account.

public void FacebookLogin(string UserAccessToken){
     var loginRequest = new LoginWithFacebookRequest(){

          TitleId = PlayFabSettings.TitleId,
          AccessToken = UserAccessToken,
          CreateAccount = true
     };

     PlayFabClientAPI.LoginWithFacebook(loginRequest, (result) =>
     {
          if (result.NewlyCreated){
               RegisterSuccess (result.PlayFabId);
          }
          else{
               FacebookLoginSuccess(result.PlayFabId);
          }
     }, (error) =>
          {
               Debug.Log("Error Login with Facebook");
               Debug.Log("HTTP: " + error.HttpCode);
               Debug.Log ("HTTP Status: " + error.HttpStatus);
               Debug.Log("Error Detail: " + error.ErrorDetails);
               Debug.Log("Error Message" + error.ErrorMessage);
               PlayFabErrorHandler.HandlePlayFabError(error);
               PlayFabErrorPopup (error);
          });
     }

 


When I test the Facebook Token on the https://api.playfab.com/Documentation/Client/method/LoginWithFacebook, the result is

{
 "code": 400,
 "status": "BadRequest",
 "error": "AccountNotFound",
 "errorCode": 1001,
 "errorMessage": "User not found",
 "CallBackTimeMS": 1726
}

 

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

If the UserAccessToken is exactly the same between the two, I would expect the same result. Can you also show us the code snippet for how you're getting the token and passing it to your FacebookLogin function? Also, what Title ID is this for?

10 |1200

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

aliceconnex@gmail.com avatar image
aliceconnex@gmail.com answered

The above code is in PlayFabManager.csfile. Here is what I use to get the User Access Token in FacebookManager.cs.

 

void Awake (){

     FB.Init (SetInit, OnHideUnity);
}

 

void SetInit(){
     if (FB.IsLoggedIn) {
          Debug.Log ("FB is logged in");
          isFacebookLoggedin = true;
          Debug.Log ("(1)" + AccessToken.CurrentAccessToken.UserId);          // Use to debug the User Access Token
     } else {
          Debug.Log ("FB is not logged in");
          isFacebookLoggedin = false;
     }
}

 

void OnHideUnity(bool isGameShown){
     if (!isGameShown) {
          Time.timeScale = 0;
     } else {
          Time.timeScale = 1;
     }
}

 

void Start (){
     if (FB.IsLoggedIn) {
          Debug.Log ("FB is logged in");
          Debug.Log ("(1)" + AccessToken.CurrentAccessToken.UserId);
          PlayFabManager.instance.FacebookLogin (AccessToken.CurrentAccessToken.UserId);
     } else {
          Debug.Log ("FB is not logged in");
     }
}

 

public void FBlogin (){
     List<string> permission = new List<string> ();
     permission.Add ("public_profile");
     FB.LogInWithReadPermissions (permission, AuthCallBack);
}

 

void AuthCallBack(IResult result){
    if (result.Error != null) {
        Debug.Log (result.Error);
    } else {
        if (FB.IsLoggedIn) {
            Debug.Log ("FB is logged in");
           Debug.Log ("(2)" + AccessToken.CurrentAccessToken.UserId);
            PlayFabManager.instance.FacebookLogin (AccessToken.CurrentAccessToken.UserId);
        } else {
            Debug.Log ("FB is not logged in");
       }
    }
}

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

Thanks - that helps. In that code, you're calling FacebookLogin with the User ID - the function needs the actual user access token for us to be able to sign the user in. On our side, we use the access token to validate the user with Facebook, and from that get a valid User ID.

10 |1200

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

aliceconnex@gmail.com avatar image
aliceconnex@gmail.com answered

Oh, Thanks a lot! Now I've test my user token which comes directly from Facebook Developer Page (developers.facebook.com) on the page https://api.playfab.com/Documentation/Client/method/LoginWithFacebook and it works!!! 

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

Congrats! Let us know if you run into any other issues.

10 |1200

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

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.