question

willwhittaker avatar image
willwhittaker asked

PlayFabError(NotAuthenticated, X-Authentication HTTP header contains invalid ticket, 401 Unauthorized)

I'm trying to get/set the VirtualCurrency values in Unity, yet I get the above error when I print out the error results. I have the following check in place:

if (!PlayFabClientAPI.IsClientLoggedIn()) { Debug.Log("SyncCurrency: Not Logged In"); return; }

I know the client is logged in, but when I try to use:

PlayFabClientAPI.AddUserVirtualCurrency();

All that happens is I get that error. Not sure what to do to fix it.

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.

willwhittaker avatar image willwhittaker commented ·

Correction, the error shows up when I call PlayFabClientAPI.GetUserInventory(); not AddUserVirtualCurrency.

0 Likes 0 ·
brendan avatar image
brendan answered

The Unity SDK is checking that the auth token (Session Ticket, for Client API calls) exists in the IsClientLoggedIn function, but in general, there's no guarantee that your next Client API call won't fail due to the ticket having expired. You should always make sure to handle the invalid ticket case, and sign the user back in when it occurs.

10 |1200

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

willwhittaker avatar image
willwhittaker answered

Never mind, the solution to this was I had to do this first:

if (!PlayFabPlayerModel.SessionToken.Equals(string.Empty)) { PlayFab.Internal.PlayFabHttp.SetAuthKey(PlayFabPlayerModel.SessionToken); }

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 ·

Thanks - I'll work with the tools team on this. The auth key should be set automatically when you log in.

1 Like 1 ·

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.