corporate avatar image
corporate asked

Intended algorithm for retrieving leaderboard FB portraits and names?

Hi all -

I am working on implementing leaderboard functionality into my game; as part of it, users should be able to access a leaderboard containing their Facebook friends where they will see their friends' FB names, portraits, score, and ranking.

I've managed to get all of those up and running, but I know already that the way I retrieve FB information is wrong. Specifically, I start by querying the retrieved entries for their Facebook account information (based on their PlayFab IDs), then query *that* data for portraits and texts, then put things into lists and arrays, then merge it all together, then pray to all the known and unknown gods of programming for it work.

I know that querying all of them in such a manner is a no-no and I'm looking for a better solution - however, I just can't seem to figure out the intended process for retrieving Facebook-specific data and associating it with each leaderboard entry. I've spent some time figuring out the ProfileConstraints feature of GetFriendLeaderboardAroundPlayerResult, but while it does return Facebook accounts, it doesn't actually return their Facebook account IDs, does it? Or am I missing something?

Would be very grateful for your help.



Leaderboards and StatisticsFriends
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

Well, you're definitely correct that hammering the service with calls to request data separately for each player in a leaderboard isn't valid (and could result in the title being throttled). But we've provided access to the profile data in the leaderboard results (via the ProfileConstraints in the query) specifically to give you the rich data you need to create leaderboards. Since what you want is specifically name, portrait, score, and ranking, that's straightforward enough. The score and rank are, of course, basic to the leaderboard results. For the name and portrait, you could either store the name as the Title Display Name (you'll need to make TDNs non-unique in your title, for Facebook) and the portrait link as the AvatarURL, and then just get those in the results, or you could use a Cloud Script to query for the player's linked account info and filter down the results to just what the user needs (I can't recommend turning on the linked account info for client queries, since all linked account info shows up in that case).

10 |1200

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

corporate avatar image corporate commented ·

Thanks, @Brendan! Question: is the Avatar URL automatically set to be the user's Facebook picture URL when they link a Facebook account? If I could simply go by the picture URL retrieved, that would make it all that much simpler.

Also, and pardon me if I'm missing something obvious, how would I store their title display name if it's supposed to be identical to their Facebook ID name (which I don't yet know, since I haven't retrieved their Facebook information anywhere in the above process)?

Or is CloudScript the only way to go here? I was rather hoping to avoid that part.

0 Likes 0 ·
brendan avatar image brendan corporate commented ·

No, you would need to set the image URL explicitly. For the Title Display Name, you would set it once the player links Facebook to their account, using

0 Likes 0 ·
corporate avatar image corporate brendan commented ·

@Brendan - Thank you! I will give it a shot tonight, but I can totally see how this would work.

0 Likes 0 ·
Show more comments
plourdegui avatar image plourdegui commented ·

@corporate, @Brendan

corporate's solution presents a caveat.

If Facebook's fullname length is higher than 25 chars, the call to UpdateUserTitleDisplayName will fail because PlayFab's limit for DisplayName is 25 chars.

What would be the recommended approach then?

Truncate Facebook fullname to make sure it fulfills the constraints imposed by PlayFab's DisplayName field?

0 Likes 0 ·
brendan avatar image brendan plourdegui commented ·

Actually, there are two issues - one is length, but the other is uniqueness. Facebook has tons of people whose fullname match those of others. So you also need to ask yourself whether you want to turn on non-unique display names in your title. If you do, you will never be able to use the display name as a lookup in search, as it would no longer be an indexed value - and we cannot reverse that once you've set a title to non-unique display names.

Ultimately, this is going to come down to how you want the user experience to work. Some titles will truncate and allow non-unique, some will truncate to even less and put a generated GUID (or similar) on the end, to make sure it's unique.

But I'll add that most titles don't use the Facebook fullname as a display name at all, as many users don't like having their real name exposed to strangers.

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.