Get playlist ID from youtube video

803 Views Asked by At

Is there any way to find playlist ID of youtube video using API, like through videoID? I looked into /playlistItems endpoint but I'm not sure where I can find the playlist item ID? I've tried to look this over everywhere but I'm at lost.

2

There are 2 best solutions below

2
Chris On

I looked a bit, and the only method I can find would be limited to your own playlists and playlists on the video's channel (or other channels that you specify):

  1. Get the video ID
  2. If you want to check playlists on the same channel, get the channel ID from the video (see https://developers.google.com/youtube/v3/docs/videos#resource)
  3. Get the playlists you want to check (https://developers.google.com/youtube/v3/docs/playlists/list) - either your own playlists or playlists on
  4. Loop through and get the items on each playlist (https://developers.google.com/youtube/v3/docs/playlistItems/list as you found)
  5. Look for the playlist item that has the same video ID as the one you're examining (https://developers.google.com/youtube/v3/docs/playlistItems#resource)

It's a bit ugly, and limited of course - maybe someone else will share a better method with us.

1
Marco Aurelio Fernandez Reyes On

An alternative could be:

  1. Since you have the video_id, get the title of the video as well.
  2. With the title of the video, use the search:list endpoint for search playlists that matches with the query/criteria - that is, the title of the video.
  3. Loop the results from the search request and use the code I show in my answer for check if the video_id is on the playlist.

Example:

video_id: eJjbnFZ6yA8

title: FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999

Make search to get playlists that matches the search term: "FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999"

URL:

https://youtube.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=50&q=FULL%20MATCH%20-%20The%20Rock%20vs.%20Mankind%20%E2%80%93%20WWE%20Championship%20Match%3A%20Raw%2C%20Jan.%204%2C%201999&type=playlist&key=[YOUR_API_KEY]

Try-it here

From the results of the search, get the playlist - for this example I took the first result I got from the search, then, I check if the video_id eJjbnFZ6yA8 is on the playlist PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W

URL:

https://youtube.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet&playlistId=PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W&videoId=eJjbnFZ6yA8&key=[YOUR_API_KEY]

Try-it here for check the results.

Keep in mind that the search:list endpoint consumes 100 quota points, so, the quota might be drain rather quickly - depending of the intensity of the search.