Sometimes, we want to get information on a single YouTube video via JSON in JavaScript.
In this article, we’ll look at how to get information on a single YouTube video via JSON in JavaScript.
Get Information on a Single YouTube Video via JSON in JavaScript
To get information on a single YouTube video via JSON in JavaScript, we can use fetch
to fetch the data from YouTube’s JSON API.
For instance, we can write:
const videoId = 'VA770wpLX-Q';
(async () => {
const res = await fetch(`https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=${videoId}&format=json
`)
const data = await res.json()
console.log(data)
})()
to fetch the JSON data with fetch
from YouTube’s JSON API.
We just call res.json
to convert the JSON data to an object.
Conclusion
To get information on a single YouTube video via JSON in JavaScript, we can use fetch
to fetch the data from YouTube’s JSON API.