question

robertb97b avatar image
robertb97b asked

How to remove group members via Server API?

The documentation for groups, has a section that explains server vs client functions for groups, says server api needs only developer secret key and can perform any actions.

Last section at: https://learn.microsoft.com/en-us/gaming/playfab/features/social/groups/quickstart

I haven't found a way to remove members from groups from my custom backend (Azure Functions Cloudscript), because it always says that the entity is Unauthorized to remove members (using the PlayfabGroupsAPI.RemoveMembersAsync with a dummy Authentication Context).

PlayFabServerAPI doesn't have a method for removing group members, neither does PlayfabAdminAPI.

Any help is appriciated.

CloudScript
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

·
Xiao Zha avatar image
Xiao Zha answered

I have tested the RemoveMembers API with title entity token, it works fine. And the error message indicates that your AuthenticationContext may be set incorrectly. Also, here is the working code you may refer to:

  public static class RemoveGroupMember
         {
             [FunctionName("RemoveGroupMember")]
             public static async Task<dynamic> Run(
                 [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
                 ILogger log)
             {
                 var context=JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());    
                    
        
                 PlayFabSettings.staticSettings.TitleId=Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID",EnvironmentVariableTarget.Process);
                 PlayFabSettings.staticSettings.DeveloperSecretKey=Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process);
        
                 var titleContext=new PlayFabAuthenticationContext()
                 {
                     EntityToken=context.TitleAuthenticationContext.EntityToken,
                     EntityId=Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID",EnvironmentVariableTarget.Process),
                     EntityType="title"
                 };
        
                 var result = await PlayFabGroupsAPI.RemoveMembersAsync(new PlayFab.GroupsModels.RemoveMembersRequest{
                     AuthenticationContext=titleContext,
                     Group=new PlayFab.GroupsModels.EntityKey{
                         Id="xxxx"
                     },
                     Members=new List<PlayFab.GroupsModels.EntityKey>{
                         {
                             new PlayFab.GroupsModels.EntityKey{
                                 Id="xxxx",
                                 Type="title_player_account",                          
                             }
                         }
                     }
                 });
                    
                 return result;
             }
         }
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.