Skip to content

Commit afbc218

Browse files
author
Justin
committed
Fix problem with appid filter on GetOwnedGames.
1 parent e9ae1a1 commit afbc218

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

src/SteamWebAPI2/Interfaces/PlayerService.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using Steam.Models.SteamCommunity;
1+
using Newtonsoft.Json;
2+
using Steam.Models.SteamCommunity;
23
using SteamWebAPI2.Models.SteamCommunity;
34
using SteamWebAPI2.Models.SteamPlayer;
45
using SteamWebAPI2.Utilities;
56
using System;
67
using System.Collections.Generic;
7-
using System.Collections.ObjectModel;
8+
using System.Net;
89
using System.Threading.Tasks;
910

1011
namespace SteamWebAPI2.Interfaces
@@ -45,7 +46,7 @@ public PlayerService(string steamWebApiKey, ISteamWebInterface steamWebInterface
4546
}
4647

4748
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
48-
ISteamWebResponse<PlayingSharedGameResultContainer>,
49+
ISteamWebResponse<PlayingSharedGameResultContainer>,
4950
ISteamWebResponse<ulong?>>(steamWebResponse);
5051

5152
return steamWebResponseModel;
@@ -145,16 +146,20 @@ public async Task<ISteamWebResponse<OwnedGamesResultModel>> GetOwnedGamesAsync(u
145146
if (includeFreeGames.HasValue) { includeFreeGamesBit = includeFreeGames.Value ? 1 : 0; }
146147

147148
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
148-
parameters.AddIfHasValue(includeFreeGamesBit, "include_played_Free_games");
149-
parameters.AddIfHasValue(steamId, "steamid");
150-
parameters.AddIfHasValue(includeAppInfoBit, "include_appinfo");
151149

152-
// join the app ids by commas since that's what the Steam Web API expects
153-
if (appIdsToFilter != null)
150+
var inputJsonObj = new
154151
{
155-
string appIdsDelimited = String.Join(",", appIdsToFilter);
156-
parameters.AddIfHasValue(appIdsDelimited, "appids_filter");
157-
}
152+
steamid = steamId,
153+
include_played_Free_games = includeFreeGamesBit,
154+
include_appinfo = includeAppInfoBit,
155+
appids_filter = appIdsToFilter
156+
};
157+
var inputJson = JsonConvert.SerializeObject(inputJsonObj, new JsonSerializerSettings()
158+
{
159+
NullValueHandling = NullValueHandling.Ignore
160+
});
161+
162+
parameters.AddIfHasValue(WebUtility.UrlEncode(inputJson), "input_json");
158163

159164
var steamWebResponse = await steamWebInterface.GetAsync<OwnedGamesResultContainer>("GetOwnedGames", 1, parameters);
160165

src/SteamWebAPI2/Utilities/SteamWebRequest.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Newtonsoft.Json;
2-
using SteamWebAPI2.Utilities;
32
using System;
43
using System.Collections.Generic;
54
using System.Diagnostics;
5+
using System.Linq;
66
using System.Net;
77
using System.Net.Http;
88
using System.Threading.Tasks;
@@ -122,14 +122,16 @@ private async Task<ISteamWebResponse<T>> SendWebRequestAsync<T>(HttpMethod httpM
122122
httpResponse = await httpClient.PostAsync(command).ConfigureAwait(false);
123123
}
124124

125+
var headers = httpResponse.Content?.Headers;
126+
125127
// extract http headers that we care about
126128
SteamWebResponse<T> steamWebResponse = new SteamWebResponse<T>()
127129
{
128-
ContentLength = httpResponse.Content.Headers.ContentLength,
129-
ContentType = httpResponse.Content.Headers.ContentType.MediaType,
130-
ContentTypeCharSet = httpResponse.Content.Headers.ContentType.CharSet,
131-
Expires = httpResponse.Content.Headers.Expires,
132-
LastModified = httpResponse.Content.Headers.LastModified,
130+
ContentLength = headers?.ContentLength,
131+
ContentType = headers?.ContentType?.MediaType,
132+
ContentTypeCharSet = headers?.ContentType?.CharSet,
133+
Expires = headers?.Expires,
134+
LastModified = headers?.LastModified,
133135
};
134136

135137
// deserialize the content if we have any as indicated by the response code
@@ -152,7 +154,7 @@ private async Task<ISteamWebResponse<T>> SendWebRequestAsync<T>(HttpMethod httpM
152154
/// <param name="methodVersion">Example: 1</param>
153155
/// <param name="parameters">Example: { key: 8A05823474AB641D684EBD95AB5F2E47 } </param>
154156
/// <returns></returns>
155-
private string BuildRequestCommand(string interfaceName, string methodName, int methodVersion, IList<SteamWebRequestParameter> parameters)
157+
private string BuildRequestCommand(string interfaceName, string methodName, int methodVersion, IEnumerable<SteamWebRequestParameter> parameters)
156158
{
157159
Debug.Assert(!String.IsNullOrWhiteSpace(interfaceName));
158160
Debug.Assert(!String.IsNullOrWhiteSpace(methodName));
@@ -166,7 +168,7 @@ private string BuildRequestCommand(string interfaceName, string methodName, int
166168
string commandUrl = String.Format("{0}/{1}/{2}/v{3}/", steamWebApiBaseUrl, interfaceName, methodName, methodVersion);
167169

168170
// if we have parameters, join them together with & delimiter and append them to the command URL
169-
if (parameters != null && parameters.Count > 0)
171+
if (parameters != null && parameters.Count() > 0)
170172
{
171173
string parameterString = String.Join("&", parameters);
172174
commandUrl += String.Format("?{0}", parameterString);

0 commit comments

Comments
 (0)