How to retrieve and iterate through steam friends

So, I’d like to retrieve the steam friends of a user. I’m using GameSparks for session handling and only integrated steam so users can authenticate with it. Oddly, GameSparks only stores avatars of friends who haven’t played the game yet. You apparantly can only retrieve the user name through a GS ListGameFriends request. So I’ll probably have to retrieve all steam friends, filter those who have already played the game and then retrieve the avatar through the steam api… (if you know a better way, please tell me).

However, I haven’t found a function to actually get all friends of a user. ISteamUser is supposed to have a getFriendList function, but it’s not showing up for SteamUser(). SteamFriends() also don’t have a fitting function (there’s only one where you can count friends, but it needs an iterator I cannot create).

Thanks in advance.

but it needs an iterator I cannot create

Why can’t you create this iterator?

Well, the function I wanted to use is the GetFriendCount() function. I thought I could just use that as length and iterate through it, to then use the GetFriendByIndex() function to actually get the friends. But both functions require a EFriendFlags as iterator for the GetFriendCount function which also has to be the same value as for the GetFriendByIndex one. I’m just not sure if it is as easy as that: can you just create a flag, put it into the count function and that return value into the GetFriendByIndex? I’m a little bit confused about the function descriptions since it seems like it’s already looping through all specified friends, but only returns one friend

So after some more research (the steam api docs are huge) I found a solution. I was actually on the right way. Here’s my code:

TArray<FSteamPlayer> AControllerFunctions::getSteamFriends(int offset) {
	
	// Array of all regular steam friends
	TArray<FSteamPlayer> friends;
	friends.Reserve(10);

	// Number of friends, used to break the loop
	int maxFriends = getSteamFriendsCount();

	// Empty CSteamID object to check if there's no friend to get left
	// You can't just check if it's null for some reason
	CSteamID zero;	

	// Temp var, holding the current friend from the loop
	CSteamID temp = SteamFriends()->GetFriendByIndex(offset, k_EFriendFlagImmediate);

	while (offset <= maxFriends || temp != zero) {
		
		temp = SteamFriends()->GetFriendByIndex(offset, k_EFriendFlagImmediate);

		// Create custom struct holding username and avatar
		FSteamPlayer steamplayer;
		steamplayer.username = SteamFriends()->GetFriendPersonaName(temp);
		steamplayer.avatar = getSteamAvatar(SteamFriends()->GetSmallFriendAvatar(temp));
		
		friends.Add(steamplayer);
		offset++;
	}
	
	return friends;
}