question

usachovdailymagic avatar image
usachovdailymagic asked

Get multiple public or internal data of several accounts at one request,Get multiple public player data

Hello everyone!
Server SDK has 2 methods "GetPlayerData" and "GetPlayerInternalData". Both of them have first parameter "PlayFabId": "2039475", . I want to get data for several account at one request. For example "PlayFabId": ["2039475","3039475","4039475"]

Is it possible to solve this problem? May be there is a method with this option to get player data for several accounts per one method call? I want to get my friends game progress in my project, and do not want to call "GetPlayerInternalData" each time for each user, just want to call it once and get all of them.

Thanks!

,

Hello everyone! Server SDK Has 2 methods - "GetUserInternalData" and "GetUserData". There is a first parameter - "PlayFabId": "2039475", which represents the account whose data I want to receive.
Is it possible to receive data for several accounts at one request? For example "PlayFabId": ["2039475","2039475","2039475",]
Can you tell any server method to get public or internal data of different accounts per one request. I want to get my friends game progress with a help of solution.

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's helpful. Your statement that this would be an extremely expensive operation for a user with a lot of friends is very true - iterating across all of a user's friends and querying for data would incur higher data costs. That's why I would recommend finding a way to do this using statistics and leaderboards. So, report the user's progress as a numeric value to a statistic. That will then let you query a list of those values in one call using our leaderboard functionality. In particular, I would recommend having a look at GetFriendLeaderboard and GetFriendLeaderboardAroundPlayer.

2 comments
10 |1200

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

usachovdailymagic avatar image usachovdailymagic commented ·

Thanks for explanation!

0 Likes 0 ·
dragonfoundry avatar image dragonfoundry commented ·

We do this to display avatar portraits for each friend. Each avatar is mapped to a numeric value, and the values are stored in the leaderboard. Makes life super-easy!

0 Likes 0 ·
brendan avatar image
brendan answered

Can you expand upon the intended gameplay mechanic you have in mind? For example, you said this is so that you can get the progress state for your friends - one way you might do this is by saving a score for each player, or even using a statistic as a bitfield to store information about their state, and then getting a friend leaderboard, which would return all that info for the player's friends.

If the need is for more complex data, one thing to bear in mind is that you are limited on the number of keys you can get at one time, so you'd only be able to get one key each for a few players this way. But again, if you can describe in more detail the feature, we may be able to help you come up with alternative solutions.

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.

usachovdailymagic avatar image usachovdailymagic commented ·

I have a public field in data section called "Score" which represents my short game progress of player. When I get friends from facebook who plays this game then I want to receive their "Score"(game progress) to show friends progress results.


screen-shot-2016-07-05-at-100024-am.png

At this moment I can see only one soultion:

var result = {};
for (var i = 0; i < ids.length; i++) {
	var data = server.GetUserData({
		PlayFabId: ids[i],
		Keys: ["Scores"]
	});
	result[ids[i]] = data.Data[Scores];
};

I have to run many queries to get all users progress. And it could be very expensive operation.

0 Likes 0 ·
usachovdailymagic avatar image
usachovdailymagic answered

Brendan, thanks for the answer. Now I will expand my question.

I have a public field in internal data section called "Score" which represents my short game progress of player.
I have a possibility to login from facebook. When I get friends from facebook who plays this game then I want to receive their "Score"(game progress) to show friends progress results.

screen-shot-2016-07-05-at-100024-am.png

At this moment I can see only one soultion:

var result = {};
for (var i = 0; i < ids.length; i++) {
	var data = server.GetUserData({
		PlayFabId: ids[i],
		Keys: ["Scores"]
	});
	result[ids[i]] = data.Data[Scores];
};
But I have to run many queries to get all users progress. And it could be very expensive operation If I have more than 50 friends who plays my game.
Is there any another solution to make it faster and at one query?

10 |1200

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

usachovdailymagic avatar image
usachovdailymagic answered

Brendan. Help me again!

I have over 50 levels, I want to collect friend's statistic on each level for all friends at one request.
If I use "GetFriendLeaderboardAroundPlayer" I get many friend's data but one "StatisticName", so this represents 1 level for me per one request.

If I use "GetPlayerStatistics" I can get many "StatisticName" but only one player, and I guess that "GetPlayerStatistics" can access only current player. I can't ask for friend's statistic with a help of "GetPlayerStatistics".

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

Later, we'll be providing a way to subscribe to events, which will help with this. But attempting to pull many statistics across many players all at once, again, would be very expensive and so not something we can support. Right now, you would need to stage out the calls to get the statistics for the players over time, so that you're not hitting the service with too many calls too quickly. This is fairly common for the type of game you're describing, with the details of levels filling in over time as the game loads the data from the service. Basically, query a leaderboard, then wait a few seconds and query the next one, etc.

Two optimizations that will help:

First, use a leaderboard to track the last time the player reported a score against any level. Grab that leaderboard first, and keep track of the last time you queried the leaderboards in local data. That way, if no on else has updated any scores since the last time you retrieved the scores, you know you don't need to do anything.

Also, in most cases the player can only see a few levels at a time, so using an "area of interest" logic for this, so that you're loading the levels in the current view first would be a way to optimize this, as well.

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.

usachovdailymagic avatar image usachovdailymagic commented ·

Thanks, I understand and will try to optimize my requests with some loading logic compatible with Playfab service.

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.