question

battlepolygon avatar image
battlepolygon asked

AddMembers

Привет всем. Есть кто-то с документацией. Как добавить человека в группу. Там нет документации нигде. Я не могу снять токен.

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.

battlepolygon avatar image battlepolygon commented ·
Hello everyone. There is someone with the documentation. How to add a person to a group. There is no documentation anywhere. I can not withdraw the token.
0 Likes 0 ·

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi @battlepolygon,

I can see you also posted the code in this thread, I believe they are related, so I am answering here.

“Only requests using a Title principal may directly add members to groups” means that the entity token you used for the AddMembers API was not a title entity token, for instance, a title_player_account entity token. You must first retrieve the title entity token using the GetEntityToken API and then pass it to the AddMember API, I made some modifications to your code:

public static void AddMemberToGroup()
    {
        PlayFabGroupsAPI.AddMembers
        (
            new AddMembersRequest
            {
                Group = new EntityKey { Id = "group id of your title" },
                Members = new List<EntityKey> { new EntityKey { Id = "title player entity of your player", Type = "title_player_account" } },
                AuthenticationContext = new PlayFabAuthenticationContext()
                {
                    EntityToken = " title entity token retrieved from the GetEntityToken API"
                }
            },
            (result) =>
            {
                Debug.Log("success");
            },
            (error) =>
            {
                Debug.Log(error.ErrorMessage);
            }
        );
}



Once you retrieved the title entity token (it’s suggested that you do it from server side since it would expose the secret key to the client) and pass it in the AuthenticationContext property, the AddMembers API should work properly.

Moreover, you can consider moving the “add members” logic to the Cloud Script, which safer and simper. There is no need to call GetEntityToken to retrieve the title entity token first, calling entity.AddMember() should do the work.

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.