max avatar image
max asked

Cloud Script GetFriendsList - Facebook Token expired - How to check?

We're currently have the issue that we didn't know that we need need update the User's Facebook token from time to time in order to be able to get their Friend List with Facebook friends.

Therefore, currently one of our Cloud Script calls is crashing with this error

"errorMessage": "(OAuthException - #190) Error validating access token: Session has expired on Friday, 05-Jan-18 07:01:29 PST. The current time is Saturday, 06-Jan-18 11:36:02 PST.",

A few questions about that:

1) What is the designated way to update the Facebook Token, is it calling LoginFacebook from time to time?

2) The error code for this is 1143 (so the standard facebook API error according to the PlayFabError.h in our C++ Client SDK). Are the PlayFab error codes available in Cloud Script, so we can check for them? Or should we manually define all the error codes that we need?

3) Can we somehow check if the Facebook Token is outdated in CloudScript? Or do we need to waste an API Call with a try/catch to see if GetFriends will return an error?

Thanks for taking the time to help :)

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

Yes, our ability to make calls to Facebook on behalf of the user depends upon us having a current token. Facebook will not provide a token with no expiration in this scenario, so you need to periodically use LoginWithFacebook to update us. For most games, just doing that at the start of the player's session is all you need.

In Cloud Script, what you'll want to do is use a try/catch to be able to evaluate the error that occurred and take any additional action based upon it.

Unfortunately, there isn't a way to check the token from Facebook to see if it is current. But in general, service tokens tend to last for hours, so for most games, this should rarely be an 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.

max avatar image max commented ·

Okay cool thanks, so 1) and 3) are answered. :)

How about 2) and the erorr constants in Cloud Script? ;)

0 Likes 0 ·
brendan avatar image brendan max commented ·

Well first, yes, the error you capture in the try/catch will have all the error details, which you can parse and use. However, I do need to point out that if you make a call to GetFriendsList for a player using a valid PlayFab ID, it will successfully return the friends for that player. If you happen to specify IncludeFacebookFriends for a player who doesn't have an up-to-date token, it still successfully returns what it can - it does not return an error.

0 Likes 0 ·
max avatar image max brendan commented ·

Thanks. Okay first. I know that I can parse and use the erorr - sorry if I was unclear. I was wondering if all the PlayFab Error constants would be actually present in the Cloud Script environment. Like 'server' is a global variable, maybe also all the error codes are? Or do we have to just check with the error code pure numbers and there are no global variables set up for that?

Second, if the GetFriendsList call is meant to return even if the Facebook token is invalid...then this might a bug, since it does return an error for us in this case. I've sent you our Title ID and CloudScript event ID privately in the Community slack channel if you want to have a look.

I also recently reported the friend-tag-profile-constraints-bug ( of GetFriendList - so maybe this might be not the only one?

0 Likes 0 ·
Show more comments
Luc avatar image
Luc answered

You can copy PlayFabErrors.cs from the SDK into your JS project to help you with the actual code <=> enum conversion. Use regex to convert from enum to int => string object. Here's a sample list:

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.