T
TDgoins1999
Guest
Hey all I am trying to figure this IGDB api out. I'm sure its powerful but it seems difficult to know what needs to be called and how since they don't have very good examples in their documents.
So as an example say I am looking to get the box art and game info from the game "Mortal Kombat" and that I need it from the SNES version.
Doing a normal search on their website brings up a lot of different Mortal Kombat.
The Mortal Kombat that I am needing for the SNES is the 2nd to last here in the image. Mortal Kombat (1992).
So I first have code to get id, cover, genres, name, platforms and screenshots:
public partial class Gameinfo
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("cover")]
public long Cover { get; set; }
[JsonProperty("genres")]
public long[] Genres { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("platforms")]
public long[] Platforms { get; set; }
[JsonProperty("screenshots")]
public long[] Screenshots { get; set; }
}
using (var client = new HttpClient()) {
using (var httpClient = new HttpClient { BaseAddress = baseAddress }) {
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("user-key", "##########################");
using (
var response = await httpClient.GetAsync("games?search=" + HttpUtility.UrlEncode(game) + "&fields=*")
)
{
string responseData = await response.Content.ReadAsStringAsync();
gameData = JsonConvert.DeserializeObject<List<Gameinfo>>(responseData);
System.Diagnostics.Debug.WriteLine(gameData);
}
}
}
The JSON response to the above is:
You can see the first hit is Mortal Kombat II and the second is the one I am looking for, the original Mortal Kombat. So from the code above I get 2 main things I need in order to search "deeper". The Game **ID** and the **Platforms** ID(s). But with saying that - there lye's the problem. I am unable to just search for Mortal Kombat and automatically get the correct 1992 version.
So without knowing the date that a game came out how can I search for the correct game with the needed platform of SNES?
UPDATE 1
So I tried doing the following:
using (
var response = await httpClient.GetAsync("games/?search=" +
HttpUtility.UrlEncode("mortal kombat") +
"&fields=name,platforms.name&where platforms.id = 19")
But I always end up with the same data no matter what:
[
{
"id": 81899,
"name": "Mortal Kombat \u0026 Mortal Kombat II",
"platforms": [
{
"id": 22,
"name": "Game Boy Color"
}
]
},
{
"id": 119,
"name": "Mortal Kombat",
"platforms": [
{
"id": 6,
"name": "PC (Microsoft Windows)"
},
{
"id": 9,
"name": "PlayStation 3"
},
{
Continue reading...
So as an example say I am looking to get the box art and game info from the game "Mortal Kombat" and that I need it from the SNES version.
Doing a normal search on their website brings up a lot of different Mortal Kombat.
The Mortal Kombat that I am needing for the SNES is the 2nd to last here in the image. Mortal Kombat (1992).
So I first have code to get id, cover, genres, name, platforms and screenshots:
public partial class Gameinfo
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("cover")]
public long Cover { get; set; }
[JsonProperty("genres")]
public long[] Genres { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("platforms")]
public long[] Platforms { get; set; }
[JsonProperty("screenshots")]
public long[] Screenshots { get; set; }
}
using (var client = new HttpClient()) {
using (var httpClient = new HttpClient { BaseAddress = baseAddress }) {
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("user-key", "##########################");
using (
var response = await httpClient.GetAsync("games?search=" + HttpUtility.UrlEncode(game) + "&fields=*")
)
{
string responseData = await response.Content.ReadAsStringAsync();
gameData = JsonConvert.DeserializeObject<List<Gameinfo>>(responseData);
System.Diagnostics.Debug.WriteLine(gameData);
}
}
}
The JSON response to the above is:
You can see the first hit is Mortal Kombat II and the second is the one I am looking for, the original Mortal Kombat. So from the code above I get 2 main things I need in order to search "deeper". The Game **ID** and the **Platforms** ID(s). But with saying that - there lye's the problem. I am unable to just search for Mortal Kombat and automatically get the correct 1992 version.
So without knowing the date that a game came out how can I search for the correct game with the needed platform of SNES?
UPDATE 1
So I tried doing the following:
using (
var response = await httpClient.GetAsync("games/?search=" +
HttpUtility.UrlEncode("mortal kombat") +
"&fields=name,platforms.name&where platforms.id = 19")
But I always end up with the same data no matter what:
[
{
"id": 81899,
"name": "Mortal Kombat \u0026 Mortal Kombat II",
"platforms": [
{
"id": 22,
"name": "Game Boy Color"
}
]
},
{
"id": 119,
"name": "Mortal Kombat",
"platforms": [
{
"id": 6,
"name": "PC (Microsoft Windows)"
},
{
"id": 9,
"name": "PlayStation 3"
},
{
Continue reading...