capricornum avatar image
capricornum asked

EntityKey ClientModels vs EntityKey GroupsModels

When I successfully log in using PlayFab.ClientModels I cache the EntityToken from the LoginResult. If I understand correctly this EntityToken.Entity represents my title_player_account.

In another place I want to use that EntityToken to list all groups that I am a member of. However when I construct a ListMembershipRequest and use the EntityToken.Entity for it, I receive an error because the Entity is not one from within the GroupsModels namespace but one from the ClientModels namespace.

I am getting terribly confused. How then am I supposed to access my group memberships or my data, my files etc.

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.

capricornum avatar image capricornum commented ·


title_player_account, for most developers, represents the Player in the most traditional way.

Set the ID field to LoginResult.EntityToken.Id in the Client API, or GetEntityTokenResponse.Entity.Id in the Authentication API.

This is an extract from the microsoft documentation. However there is no such thing as LoginResult.EntityToken.Id.

In this question someone asked something similar. In the answer it says Entity.Key is what I am looking for. However there is no such thing either.

All this chaos is really frustrating.

What I am trying to do in my client build is to create a group once I am logged in. Then I quit the game, start again and log in. Now I wish to get the id's and group names of all the groups that I am a member of. "I" being the title_player_account.

0 Likes 0 ·

1 Answer

Sarah Zhang avatar image
Sarah Zhang answered

Do you use Unity C#? If so, in C#, these two types -- ClientModels.EntityKey and GroupsModels.EntityKey can’t be implicitly converted to each other. If you want to convert the ClientModels.EntityKey object to the GroupsModels.EntityKey object, the possible workaround is to use JSON as the middleware. On the Unity Engine, the sample code could be something like this. Or as the thread said, you can create a mapping function for the conversion on your own.

 private void OnLoginSuccess(LoginResult result)
        PlayFab.ClientModels.EntityKey playerEntity;
        playerEntity = result.EntityToken.Entity;
        var jsonConverter = PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);
        groupAdminEntity = jsonConverter.DeserializeObject<PlayFab.GroupsModels.EntityKey>(jsonConverter.SerializeObject(playerEntity));
        var listMembershipRequest = new ListMembershipRequest { Entity = groupAdminEntity };
        PlayFabGroupsAPI.ListMembership(listMembershipRequest, OnListSuccess, OnFailure);

Besides, in the ListMembershipRequest’s body, the Entity field is optional. So, you can also keep the request body empty.

         var listMembershipRequest = new ListMembershipRequest { };
        PlayFabGroupsAPI.ListMembership(listMembershipRequest, OnListSuccess, OnFailure);
10 |1200

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

capricornum avatar image capricornum commented ·

Thank you Sarah!

When I leave the Entity field empty in the ListMembershipRequest, does PlayFab automatically get the logged in player as the entity to perform this action on? If so, that is very good to know. I feel stupid for missing it.

Thanks for your conversion suggestion. In the meantime I implemented my custom conversion:

using PlayFab.GroupsModels

EntityKey Convert(PlayFab.ClientModels.EntityKey clientKey)

  return new EntityKey() { Id = clientKey.Id, Type = clientKey.Type };
0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang capricornum commented ·

Yes, PlayFab will automatically use the logged-in player's entity to access the API.

PlayFab SDK always stores the logged-in player's entity token as the global variable. When you call the Entity API, the client's entity token would be automatically filled.

For this API, the Entity field is optional, when you leave the field empty, it will use the caller's entity automatically.

1 Like 1 ·
capricornum avatar image capricornum Sarah Zhang commented ·

Thank you Sarah! That simplifies a lot and is very helpful!

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.