Skip to content

Instantly share code, notes, and snippets.

@kaivalyapowale
Created December 17, 2019 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaivalyapowale/3fa2f20e575667453bf7b56dad267553 to your computer and use it in GitHub Desktop.
Save kaivalyapowale/3fa2f20e575667453bf7b56dad267553 to your computer and use it in GitHub Desktop.
Get Top 100 Games by Number of Viewers Twitch
# Getting data for Top 100 Games by number of viewers
# Default response is for 20 games so you will have to set the parameter 'first to 100'
headers = {
'Authorization' : 'Bearer '+str(access_token),
}
games_response = requests.get('https://api.twitch.tv/helix/games/top?first=100', headers=headers)
# The response will be a JSON which will include the response data and the pagination cursor
# We need to extract the data from the JSON and convert it into a pandas dataframe
games_response_json = json.loads(games_response.text)
topgames_data = games_response_json['data']
# Converting to a pandas dataframe
topgames_df = pd.DataFrame.from_dict(json_normalize(topgames_data), orient='columns')
# See the first few lines. The response includes id, name, and box art url for the game
topgames_df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment