How to get "last played on" for Steam game using Steam API
Surely, this data must exist within Valve's servers, but they just don't expose it for whatever reason. For now, it appears that this data is only available from the Steam client on a user's PC. After some digging, I was able to find that lastplayed timestamps are available from the following file:
\steam\userdata\{steam_id}\config\localconfig.vdf
Note, the .vdf file is a text file that can be opened in a text editor. Here's an example of one of the timestamps (Just Cause 3):
"225540"
{
"LastPlayed" "1466894369"
}
The timestamp is in epoch format and translates to 6/25/2016, 6:39:29 PM GMT-4:00 DST
You could have users upload this file from their computer and then you could parse it on your server to get the last played timestamps. It's not ideal, but it is a start.
I'm not sure what your programming language of choice is for your project, but here are some VDF parsers that can get you started:
C#:
https://github.com/sanmadjack/VDF
NodeJS:
https://www.npmjs.com/package/vdf
Python:
https://gist.github.com/strycore/5735482
EDIT April 29, 2017:
I have now discovered that it's possible to scrape this information from a user's steam games page:
http://steamcommunity.com/id/pcmantinker/games/?tab=all
By inspecting the source code of the page, I noticed that there is a JavaScript object for rendering the games. Within this object, each game has a "last_played" field available. One entry looks like this:
{
"appid":346110,
"name":"ARK: Survival Evolved",
"logo":"http:\/\/cdn.edgecast.steamstatic.com\/steamcommunity\/public\/images\/apps\/346110\/58a660ddb7ed1864656ec65e4c18d6edd3bbf512.jpg",
"friendlyURL":346110,
"availStatLinks":{
"achievements":true,
"global_achievements":true,
"stats":false,
"leaderboards":false,
"global_leaderboards":false
},
"hours":"0.5",
"hours_forever":"84",
"last_played":1492447993
}
In order to parse this information, you'll need to find the beginning and the end of the string and then parse the JSON to an object you can manipulate. At this time, the beginning of the string is "var rgGames = ["
and the end of the string is "];"
. I know this not ideal, but it does allow you to obtain this information without the need for the Steam client to be installed.
user3122306
Updated on June 24, 2022Comments
-
user3122306 about 2 years
I'm developing an App that uses public Steam API for collect some information. Currently I retrieve the achievements by calling
GetPlayerAchievements (v0001)
and total hours played callingGetOwnedGames (v0001)
. This works fine.But now I need to known also what was the last played data from a game, for example if you enter on a profile page you can see this info in html page (http://steamcommunity.com/profiles/your_steam_id_here/)
Reviewing the Steam API documentation I cannot find any api call to retrieve this information. So, can this only be obtained scraping the user profile web?
-
Edgar almost 8 yearsThat's a nice trick. However, depending on the app it might not have access to the file system.
-
Cameron Tinker almost 8 yearsI imagine that the appropriate file permissions could be granted through some sort of elevation during installation. Most application installers require elevation in order to change the file system, add registry keys, etc.
-
Cameron Tinker about 7 yearsI've updated my answer to include a nicer approach for getting last played timestamps from a webpage. This should be the preferred method as it doesn't require Steam to be installed on the user's machine.
-
panta82 almost 7 yearsThis only works if you are logged into Steam. I wouldn't like to have scraper try to do that, Steam is pretty fiddly regarding security
-
Cameron Tinker almost 7 yearsI just tested my JavaScript method and verified that my account doesn't need to be logged in for my profile. Could it be a privacy setting per user?