Can't get Steam app names?

I’m trying to implement the GetAppName function from Steam’s ISteamFriends Interface. No matter what I do, what app ID is used, or how I read it, GetAppName always returns -1, meaning it couldn’t find an app. I’ve never tried using Steam’s API before, I’ve only ever used Unreal’s online subsystems. Does anyone know where I went wrong here?

void USteamFriendsFunctionLibrary::GetSteamFriendGame(const FSteamFriend SteamFriend, ESteamFriendAsyncResultSwitch& Result, FString& GameName)
{
if (!SteamFriend.UniqueNetID.IsValid())
{
Result = ESteamFriendAsyncResultSwitch::OnFailure;
return;
}

if (SteamAPI_Init())
{
// Convert the ID to a uint64 pointer
uint64 ID = ((uint64)SteamFriend.UniqueNetID->GetBytes());

  // Get the GameInfo from the Player via ID
  FriendGameInfo_t GameInfo;
  bool bIsInGame = SteamFriends()->GetFriendGamePlayed(ID, &GameInfo);

  // If InGame and the GameID is actually valid, try to get the AppName
  if (bIsInGame && GameInfo.m_gameID.IsValid())
  {
  	char* NameBuffer = new char[1024];
  	int NameLength = SteamAppList()->GetAppName(GameInfo.m_gameID.AppID(), NameBuffer, 1024);

  	if (NameLength != -1)
  	{
  		GameName = FString(UTF8_TO_TCHAR(NameBuffer));
  	}

  	Result = ESteamFriendAsyncResultSwitch::OnSuccess;
  	return;
  }

}

Result = ESteamFriendAsyncResultSwitch::OnFailure;
}

(Sorry about the wonky formatting. It keeps changing my indents for some reason.)

Thanks in advance!

One thing to note is that the GetAppName function from Steam’s ISteamAppList Interface requires that the App List has been retrieved first using the RequestAppList function. This ensures that the list of apps is up to date before attempting to retrieve any app names.

Here’s an updated version of your function that includes a call to RequestAppList before calling GetAppName:

void USteamFriendsFunctionLibrary::GetSteamFriendGame(const FSteamFriend SteamFriend, ESteamFriendAsyncResultSwitch& Result, FString& GameName)
{
    if (!SteamFriend.UniqueNetID.IsValid())
    {
        Result = ESteamFriendAsyncResultSwitch::OnFailure;
        return;
    }

    if (SteamAPI_Init())
    {
        // Convert the ID to a uint64 pointer
        uint64 ID = ((uint64)SteamFriend.UniqueNetID->GetBytes());

        // Get the GameInfo from the Player via ID
        FriendGameInfo_t GameInfo;
        bool bIsInGame = SteamFriends()->GetFriendGamePlayed(ID, &GameInfo);

        // If InGame and the GameID is actually valid, try to get the AppName
        if (bIsInGame && GameInfo.m_gameID.IsValid())
        {
            // Request the app list before getting the app name
            SteamAppList()->RequestAppList();

            char NameBuffer[1024];
            int NameLength = SteamAppList()->GetAppName(GameInfo.m_gameID.AppID(), NameBuffer, sizeof(NameBuffer));

            if (NameLength > 0)
            {
                GameName = FString(UTF8_TO_TCHAR(NameBuffer));
            }

            Result = ESteamFriendAsyncResultSwitch::OnSuccess;
            return;
        }
    }

    Result = ESteamFriendAsyncResultSwitch::OnFailure;
}

This should ensure that the App List is up to date and increase the chances of successfully retrieving the app name with GetAppName.

Do you know where RequestAppList is declared? I can’t seem to find it anywhere, and intellisense doesn’t see it either.

Edit: I see now that there is a similar function called GetAppList, but it’s a part of the Steamworks web API, not the normal Steamworks API. Is there a way to access this?