question

giorgiotino avatar image
giorgiotino asked

Access a player's Entity Objects with an external/admin tool

Hello,

Problem:

We use Entity Objects to store a "PlayerData" value string in JSON format. e.g.

KEY "PlayerData":

VALUE {"Username" : "John Doe", "Level" : 123 }

Now we have put our game live already and we would like to stop storing the player name in our "Username" field in the Object JSON and update each player's title DisplayName accordingly.

We already have 10k players and we would like to find a way to write a tool that does the following:

1 - Retrieve the Entity Objects for every player
2 - Parse the string associated to the "PlayerData" key and extract the values of "Username"
3 - Update the Player DisplayName with such value

I am stuck at 1 because I cannot find a way to get the player's Entity Objects from an Admin Tool (e.g. the Unity Editor) because every API that I have tried requires the player to be logged in.

Is there a workaround for that?

Any idea to how I can accomplish this task?

Thanks in advance.

apisentities
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

You should perform this task at title-level, use Title Entity Token instead:

  1. Call GetEntityToken with SecretKey in exchange for Title Entity Token – Title Entity can access all the players’ entity profiles (including Objects, Lineage, etc.)
  2. Call GetProfiles with the Title Entity Token to get players’ DisplayName stored in their objects, note: this API can retrieve multiple entities in a single request so that you don’t have to retrieve one entity at a time.
  3. Update the Player DisplayName with the Admin UpdateUserTitleDisplayName API accordingly.

And, please also note that you should enable both entity and admin API in Unity in order to make the calls, if you’re a PlayFab Editor Extensions user, this can be done in the panel:

Or, if you are not a panel user, you’ll need to update defines manually, for example: Go to Edit -> Project Settings -> Player -> "PC & Mac & Linux Standalone" -> "Platform Custom Defines", Add ENABLE_PLAYFABADMIN_API.

Please let me know if you have any other questions.


1.png (5.0 KiB)
10 |1200

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

giorgiotino avatar image
giorgiotino answered

Thanks for the detailed answer,


unfortunately I was not able to accomplish the task by following exactly your suggestions, but I have found a workaround. The problem with your example is that GetProfiles

requires a list of EntityKey of the profiles I want to get info from, but my issue was exactly that I was not able to retrieve those EntityKeys in the first place.

My workaround is as follows:

  1. PlayFabAdminAPI.GetAllSegments() to retrieve a list of all segments (I know I am looking for "All Players" and I check such segment exists and I store the SegmentId)
  2. PlayFabAuthenticationAPI.GetEntityToken() as per your suggestion, in order to get the token I need for the following calls.
  3. PlayFabAdminAPI.GetPlayersInSegment() with the SegmentId I stored before. This returns a List<PlayerProfile> (I have implemented paging here and seems to work fine)
  4. I create a List<string> of each PlayerProfile's PlayerId that has DisplayName null, then I call PlayFabProfilesAPI.GetTitlePlayersFromMasterPlayerAccountIds() passing such list.
  5. This return a TitlePayerAccounts Dictionary<string, PlayFab.ProfilesModels.EntityKey> and I can at this point call PlayFabDataAPI.GetObjects() where I set the PlayFab.DataModels.EntityKey using the Type and Id of any given player.
    (btw why all those EntityKeys in different namespaces if I can just copy Id and Type and from one another?)
  6. At this point I do check if the Objects["PlayerData"] exists and I deserialize it. I read the Username and I call PlayFabAdminAPI.UpdateUserTitleDisplayName() passing the PlayFabId and the DisplayName == Username.

Now, that looks like a huge amount of steps and API calls and I don't know if I am missing a shortcut. I wish there was an Admin call to get a list of every Player and related Entity that requires only the Dev Auth Key...

Am I missing something?

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.

Citrus Yan avatar image Citrus Yan commented ·

Currently, there is no Admin call to get a list of every Player and related Entity, therefore, the steps you mentioned above are correct, and, one thing to mention: you can use GetProfiles to retrieve multiple profiles in a single request.

And, EntityKeys defined in different namespaces are pretty much the same.

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.