question

Maksim Pelevin avatar image
Maksim Pelevin asked

,How do I make a request to the player database?

,

Hi! I want to get a list of levels of players from a certain segment (who haven't played for more than 30 days). The level value is stored in PLAYERDATA. I wrote this cloud script:

var segmentList = {};
    segmentList = server.GetPlayersInSegment({
        "SegmentId": "7C11A818812533F5"
    })
    
    for(i = 0; i < segmentList.ProfilesInSegment; i++)
    {
        var playerId = segmentList.PlayerProfiles[i].PlayerId;
        
        var playerData = server.GetUserData({PlayFabId: playerId, Keys: "level"});
        if ((playerData.Data.hasOwnProperty("level")))
        {
            log.info("level:" + playerData.Data.level.Value);
        }
        
    } 

It works, but only for 25 players, and then returns an error "PlayFab API request aborted, because API call count limit exceeded".

How else can I get this information?

Player DataapisCloudScript
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

·
Seth Du avatar image
Seth Du answered

We won't recommend using this API in Cloud Script because there is runtime limit in Cloud Script and GetPlayersInSegment cannot return a consistent result since the player number is uncertain.

If you have an external server or use it locally, please always refer to the API document: https://docs.microsoft.com/en-us/rest/api/playfab/server/playstream/getplayersinsegment?view=playfab-rest#request-body.

Since there can be a large quantity of players in a segmentation and single HTTP payload is limited, PlayFab has modified the API to handle this scenario. MaxBatchSize property in the request can define the number of players returned in a callback. If the number is large, there will be a ContinuationToken in the callback, which can be used in the request of following API calls, so that you will be able to request the next batch of players. SecondsToLive is used to define the lifetime of the ContinuationToken.

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.