question

Kim Strasser avatar image
Kim Strasser asked

How can I remove a friend from the friends list?

I want that a player can remove a friend from his friends list but I don't know how to use PlayFabClientAPI.RemoveFriend. I don't know what "FriendInfo friendInfo" is.

private async Task RemovethisFriend(FriendInfo friendInfo)

How can I use RemoveFriends to remove a player from the friends list?

RemoveFriends(???);

My code to get the friends list:

  	public async void GetFriends()
        {
            await NewGetFriends();
        }

        private async Task NewGetFriends()
        {
            var request = await PlayFabClientAPI.GetFriendsListAsync(new GetFriendsListRequest()
            {
                IncludeSteamFriends = false,
                IncludeFacebookFriends = false
            });


            if (request.Error != null)
            {
                Console.WriteLine(request.Error.GenerateErrorReport());
            }
            else
            {
                Console.WriteLine("Received friends list");
                _friends = request.Result.Friends;
            }
        }

My code to remove a friend from the list:

 	public async void RemoveFriends(FriendInfo friendInfo)
        {
            await RemovethisFriend(friendInfo);
        }

        private async Task RemovethisFriend(FriendInfo friendInfo)
        {
            var request = await PlayFabClientAPI.RemoveFriendAsync(new RemoveFriendRequest()
            {
                FriendPlayFabId = friendInfo.FriendPlayFabId
            });


            if (request.Error != null)
            {
                Console.WriteLine(request.Error.GenerateErrorReport());
            }
            else
            {
                _friends.Remove(friendInfo);
                Console.WriteLine("Removed friend");
            }
        }
Player Data
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

·
Sarah Zhang avatar image
Sarah Zhang answered

FriendInfo is the object that contains some parameters about friends’ information. You can check this API to learn more. Check this quickstart about Friends to get some sample code.

When you want to remove a friend from a player's friends list, you just need to provide FriendPlayFabId. You can get this from the FriendInfo object, also can enter this Id manually. It’s only a string. If you want to get this from the FriendInfo, you need to define a FriendInfo object to store the Info whose you want to remove and pass this parameter to your RemoveFriends function.

Add a declaration.

private FriendInfo friendInfoForRemoving;

Assign a value to the variable.

...

foreach (var item in _friends)
{
	if (item.FriendPlayFabId == "xxx")// your condition
        {
        	friendInfoForRemoving = item;
        }
}
...

Pass the parameter.

...

RemoveFriends(friendInfoForRemoving);

...
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.