get youtube video revision graph

FREEMIUM
Durch Thomcle | Aktualisiert il y a 2 mois | Data
Health Check

N/A

Zurück zu allen Tutorials (1)

Plot a revision graph with API data in python

Fetch revision graph in python with requests

Here we’re going to fetch json data.

import requests
import json

url = "https://get-youtube-video-revision-graph.p.rapidapi.com/heatMarkers"
querystring = {“videoId”:“0e3GPea1Tyg”}

headers = {
“X-RapidAPI-Key”: “API_KEY”,
“X-RapidAPI-Host”: “get-youtube-video-revision-graph.p.rapidapi.com
}

response = requests.get(url, headers=headers, params=querystring)

revision_graph = response.json()

Plot revision graph of the video

We’re going to use a graph with the time in seconds on the x-axis and the intensity on the y-axis.

import matplotlib.pyplot as plt

#here, element[“startMillis”] is divided by 1000 because the initial time is expressed in millisecobes and we want it in seconds.
x = [int(element[“startMillis”])/1000 for element in revision_graph[“heatMarkers”]]

y = [element[“intensityScoreNormalized”] for element in revision_graph[“heatMarkers”]]

plt.plot(x, y, label=“Revision graph”)

plt.show()

And this is what you’ll get:
Revision graph