Home > front end >  Is it possible to get a YouTube playlist's thumbnail URL based on the playlist ID?
Is it possible to get a YouTube playlist's thumbnail URL based on the playlist ID?

Time:11-30

I have seen the following stackoverflow question about retrieving a YouTube Video's Thumbnail by ID.

I am trying to retrieve such a link so it can be displayed in a Discord Bot's Embed, which requires a direct link to the image.

The answer to that previous question works just fine, but it only works on single videos. I am curious if you can retrieve the thumbnail in a similar way from a playlist ID.

Example of direct link to a YouTube Video thumbnail:

https://img.youtube.com/vi/T7_rLD3S6mY/0.jpg

However, is it possible to create such a link using this URL?

https://youtube.com/playlist?list=PLB6y-bQdmqCE3l2nYzvUrszgbJa3kQFDi

It doesn't have to be the playlist's thumbnail. the thumbnail from the first video also works. However, I couldn't find a way to do that either, since you would have to get the first video's ID.

The final implementation will be in JavaScript, if there is a library that can help out with the solution.

CodePudding user response:

Using YouTube Data API v3 PlaylistItems: list you can retrieve the first video id from the playlist id thanks to:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLB6y-bQdmqCE3l2nYzvUrszgbJa3kQFDi&maxResults=1&fields=items(snippet/resourceId/videoId)&key=API_KEY

  • Related