syntaxerrors / Steam

A composer package to make use of the steam web api.
https://packagist.org/packages/syntax/steam-api
MIT License
160 stars 55 forks source link

No achievements returning for game because of wrong name #48

Closed Kovah closed 7 years ago

Kovah commented 7 years ago

I just encountered some problems with the API with the following game: Ace of Spaced (App ID 224540)

I tried to get all achievements for a profile by using the GetPlayerAchievements() function but it returned null. I double checked the Steam ID of the user and the App ID. Both are correct so I opened the URL the function tries to open in the browser and it returns the HTML page instead of the XML version.

Wrong URL
http://steamcommunity.com/profiles/76561198018670465/stats/AceofSpades:BattleBuilder/achievements?xml=1

Correct URL
http://steamcommunity.com/profiles/76561198018670465/stats/AceofSpades/achievements?xml=1

Okay, must be the rare case where the game name is required to return the XML data. But why does the function keeps returning null then?

While trying to get the achievements, the function tries to get the game name by running $app = $this->app()->appDetails($appId);. However, this function is returning a completely wrong game name. Instead of AceofSpades it returns AceofSpades:BattleBuilder while the App ID stays the same.

URL from $this->app()->appDetails(224540)
store.steampowered.com/api/appdetails/appids=224540&key=XXXXXX&format=json

The problem appDetails($appId) tries to get information about the game from the games store page. However, the store page may display a different game name than reported by GetOwnedGames().

Possible solution I think that a wrong API call is triggered here. Instead of using the Store API I would rather use the GetSchemaForGame() function, which may return the correct game name.

stygiansabyss commented 7 years ago

I honestly thought the appDetails method would always work here since that's all the method does is find app names. The fact that it has found an incorrect one is odd. Does get schema for game return the proper name?

Kovah commented 7 years ago

I can't test the function properly at the moment because the name looks always like this: ValveTestApp224540 This problem seem to be not that rare: from more than 600 games about 80 returned no achievements because of this problem. It seems many games have a store title that differs from the actual internal game name. :/

stygiansabyss commented 7 years ago

If achievements use the store title it may be time I brought in the storefront API.

Kovah commented 7 years ago

Could you try the GetSchemaForGame() function? It still returns ValveTestApp224540 and I'm not sure if this is a local problem or a broken Steam API.. ?!

Just tested it again. GetSchemaForGame() still returns ValveTestApp224540 as the name instead of the actual game.

Tecnology73 commented 7 years ago

I did something a little hackish and inside the GetPlayerAchievements() method I did a curl request before try { $client = ... and set $this->url to the redirect url from the curl request. I don't know if it's perfect and I haven't really tested it but it resolved appId 220 (Half-Life 2) which it's achievements appname is HL2.

If you want to give it a try and test it more insert this code just before the try { ... } catch { ... } block.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Must be set to true so that PHP follows any "Location:" header
url_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_exec($ch);
$this->url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);

Also instead of trying to resolve the appName inside the catch block, I just returned null.

stygiansabyss commented 7 years ago

@73cn0109y Your solution was fine. I cleaned up the implementation a little and pushed it out just now. I will be adding this to the next tagged release.