Categories
JavaScript Answers

How to Get Information on a Single YouTube Video via JSON in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *