babelshift / SteamWebAPI2

🎮 C# / .NET library that makes it easy to use the Steam Web API. It conveniently wraps around all of the JSON data and ugly API details with clean methods, structures and classes.
MIT License
263 stars 43 forks source link

Unable to get game info w/GetStoreAppDetailsAsync #62

Closed CriticalFlaw closed 6 years ago

CriticalFlaw commented 6 years ago

I'm making a command for a Discord bot that pulls a random game from Steam. It gets a random AppID from a preloaded list then calls GetStoreAppDetailsAsync to get the game information. For certain games, namely Team Fortress 2 it works fine but for most others it throws an error, screenshot below.

Random RND = new Random();
SteamStore steam = new SteamStore();
var index = GlobalVariables.SteamAppList.Keys.ToArray()[RND.Next(0, GlobalVariables.SteamAppList.Keys.Count - 1)];
var app = await steam.GetStoreAppDetailsAsync(index);
var output = new DiscordEmbedBuilder()
.WithTitle(app.Name)
.WithThumbnailUrl(app.HeaderImage)
.WithFooter($"App ID: {app.SteamAppId.ToString()}")
.WithColor(DiscordColor.MidnightBlue);

Apologies if this is a newbie question, I'm fairly new to working with JSON and APIs.

Thanks!

babelshift commented 6 years ago

Sorry, just realized you said TF2 is working but others aren't. I'll investigate others.

babelshift commented 6 years ago

I changed the PcRequirements, MacRequirements, and LinuxRequirements properties to dynamic since it appears that the Steam Web API returns an object or an array for these fields depending on the game. The latest nuget package should fix this issue. Let me know. Thanks.

CriticalFlaw commented 6 years ago

Downloaded the latest nuget package, it fixed the problem, thanks! Sometimes, when GetStoreAppDetailsAsync is called it'll return a null object reference exception, not sure what that's related to, so I've put it in a loop until a valid game is returned: https://github.com/CriticalFlaw/FlawBOT/commit/8dc088eb0b3b6f5ea6dafff7daf6e2077785610d