Interacting with an API can be daunting especially if the documentation is spread between wiki pages like Steam has theirs. When I first performed a Google search on how to use the Steam API, I noticed there were many libraries that had been created to make the process easier. I was so enthralled to discover this, until I realized each one that I tried to use either no longer worked or was not clear with how to use it.
Eventually, I learned how to make request to the Steam API! It was actually more simple than I thought initially. Here is how I did it:
import json
import requests
# Make Requests to Steam for all applications which include games and DLC's
URL = "https://api.steampowered.com"
data = requests.get(url="https://api.steampowered.com/ISteamApps/GetAppList/v2", ).json()
Fast-forward two days, and I realized that game ownership data was recently made unavailable as of 2018 (keep reading for details); that is until I ran across Steam Spy. So I used the Steam API to tell me which appids were actually games and then fed these ids to Steam Spy to get ownership and other data. Although the data in Steam Spy is not as accurate as it was pre-2018,, it is still very valuable because the current data is derived from historical data collected since at the latest 2014. Maybe you ask, why not just ask Steam if they have the better tools available that they promised would be developed soon in 2018. Turns out, they have no real timeline in place:
Upon further inspection of Steam Spy, it appears that the creator of Steam Spy, Sergey Galyonkin, has a Patreon account where you can even access more data. The problem is that the provided API does not provide this additional data. Therefore, I concluded that scraping would be my best plan of action. So, after checking the Privacy agreement and the Robots.txt of Steam Spy (What is a robots.txt file–click here to find out!), I felt like this was a green light to scrape. With a little help from Selenium’s chrome driver, I set my little scrapping bot to do all my bidding. Here is how I started my bot:
# Sets up a Chrome driver from default profile. NOTE: you cannot use Chrome driver and actively use Chrome at the same time or the code will # not work.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument(r'user-data-dir=C:\Users\[will be unique to you]\AppData\Local\Google\Chrome\User Data')
# Create chrome driver
driver = webdriver.Chrome(os.getcwd()+"\\chromedriver.exe", options=options)
# Go to game page on Steam Spy
appid = str([put your appid here])
driver.get("https://steamspy.com/app/" + appid)
After trial and error, I was able to collect all the data I needed to conduct my analysis into which game features result in high ownership by Steam users. Check it out here: Steam Game Analysis