Created
December 17, 2019 15:08
-
-
Save kaivalyapowale/3fa2f20e575667453bf7b56dad267553 to your computer and use it in GitHub Desktop.
Get Top 100 Games by Number of Viewers Twitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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