Is there any way to get playlists count using youtube api

581 Views Asked by At

Hi friends am trying to get the exact count of number of playlists in channel using channelid using youtube api.

1

There are 1 best solutions below

3
uzr On

Yes it is possible by using the Youtube V3 API and the playlist.list together with a channel id.

Get all playlist ids from channel id - youtube api v3 shows how to get the playlist id's from the API.

Request sent through the API explorer:

part: snippet
channelId: UCBkNpeyvBO2TdPGVC_PsPUA

A response from playlist.list

{
 "kind": "youtube#playlistListResponse",
 "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/GayOzLnLt1ndQVz5WvCaYWPuXUo\"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 14, <--- Total number of playlists.
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#playlist",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/llWSSTxPt1F74kWJeadntx0oOlU\"",
   "id": "PL2qcutlDmS0BGjOf5rwjWNH6JnyFEShyb",
   "snippet": {
     // snippet information, title etc
   }
  },
  {
   "kind": "youtube#playlist",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/D7iFaGmnjkkw29IXm-6kWaCd0a8\"",
   "id": "PL2qcutlDmS0DUCGOdr5eYDwZC_1JAReI4", 
   "snippet": {
  },
  {
   "kind": "youtube#playlist",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/0MGgZUqxHh3qkYePoEP3C9ZPamU\"",
   "id": "PL2qcutlDmS0DMB6Xv2KmlKzdOtNqMOwpv", // Count 3
   "snippet": {
        // snippet information, title etc
    }
  },
  {
   "kind": "youtube#playlist",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/XMQu1lYA_nJGBD5l7JknPncuwv0\"",
   "id": "PL2qcutlDmS0CnyV8Jcbl2d7yFxd2iGg67",
   "snippet": {
        // snippet information, title etc
   }
  }
 ]
}

You can use the totalResults from pageInfo to get the number of playlists for that channel.