Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all playlist ids from channel id - youtube api v3

I am currently learning the use of the youtube api. I want to retrieve all playlists id from a channel id. I read through the documentation and saw that I can use youtube.channels.list for such task. I did basic testing on the api_page. Still, I am not able to figure what params to use to get the playlist id. How can I retrieve all playlist ids from a given channel id?

https://www.googleapis.com/youtube/v3/channels?part=id&id=UCF0pVplsI8R5kcAqgtoRqoA&key={YOUR_API_KEY}

like image 975
Code_Ed_Student Avatar asked Nov 09 '14 18:11

Code_Ed_Student


People also ask

How do I find my YouTube playlist ID API?

To get a playlist ID, we recommend that you first run the request shown above for adding a playlist. Extract the playlist ID from the API response and use that value for the playlist you want to update. The playlist title and description used in this example are the same as those used in that example.

What is the playlist ID on YouTube?

Go to your target YouTube playlist on the browser. On the address bar, you will see something like this: https://www.youtube.com/watch?v=RLykC1VN7NY&list=PLFs4vir_WsTwEd-nJgVJCZPNL3HALHHpF. The playlist ID is the characters after “list=” so in the URL above, our playlist ID is PLFs4vir_WsTwEd-nJgVJCZPNL3HALHHpF.

What can you do with a YouTube channel ID?

A YouTube Channel ID is a unique identifier for a YouTube Channel. This ID can be used for social apps or services to show YouTube information or feeds.


2 Answers

A simple way :

With the YouTube API v3 with the ressource playlists.list

Use this parameters to get the playlists ID of a channel :

part: 'snippet'
channelId: 'UCBkNpeyvBO2TdPGVC_PsPUA'

https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}

The output :

 "items": [
  {

   "kind": "youtube#playlist",
   "etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/K21sgPQuMRCjhSMBjm3v3n5tl1o\"",
   "id": "PL2qcutlDmS0CnyV8Jcbl2d7yFxd2iGg67",
   "snippet": {
    "publishedAt": "2014-07-08T03:13:37.000Z",
    "channelId": "UCBkNpeyvBO2TdPGVC_PsPUA",
    "title": "These Things Happen Series",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/93mgU_VXZrA/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/93mgU_VXZrA/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/93mgU_VXZrA/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/93mgU_VXZrA/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/93mgU_VXZrA/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "GEazyTV"
   }
  },
  {

   "kind": "youtube#playlist",
   "etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/5ifuvTYKbyV6DUPqbTa2bnO2jWY\"",
   "id": "PL2qcutlDmS0B0jwHOQYzgRhJpnxDwPBHc",
   "snippet": {
    "publishedAt": "2014-06-05T07:36:58.000Z",
    "channelId": "UCBkNpeyvBO2TdPGVC_PsPUA",
    "title": "B-Sides",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "GEazyTV"
   }
  },
...

This is a sample example with a random channel.

If you don't know how to get the channelID of a channel use ressource channels.list:

With this parameters to get the video ID of a playlist :

part: 'id'
forUsername: 'channel_name'

https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=GEazyTV&key={YOUR_API_KEY}

 "items": [
  {

   "kind": "youtube#channel",
   "etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/vIwM6ev74Om0AOupX26jJoEDELU\"",
   "id": "UCBkNpeyvBO2TdPGVC_PsPUA"
  }
like image 57
mpgn Avatar answered Sep 19 '22 07:09

mpgn


I'm not sure how I came across this solution, but I've found that if you follow these steps then you can retrieve the playlistID to use:

  1. Create an API Key using the Google API Console.

  2. Use
    https://www.googleapis.com/youtube/v3/channels?part=contentDetails&key=[KEY FROM GOOGLE API CONSOLE]&id=[CHANNEL ID]
    where you are replacing everything, including the brackets, with the corresponding info (I find channel ids are easy to come by since they are normally in the URL. The PlaylistID is the one that tends to be difficult).

  3. The resulting feed from the URL in step 2 should contain an uploads object, containing the playlistID which is used in the URL in step 4.

  4. Use
    https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=[PLAYLIST ID RETRIEVED IN STEP 3 HERE]&key=[KEY FROM GOOGLE API CONSOLE]

The link from step 4 is what should end up being used in the app.

This works for me every time, and I integrate the YouTube v3 API in many apps. I completely agree with @Utkanos' comment that while @mpgn's answer works sometimes, it certainly doesn't work for all channels.

like image 30
John Holtkamp Avatar answered Sep 21 '22 07:09

John Holtkamp