Search code examples
iosyoutube-apiyoutube-data-apiytplayerview

How do I filter out videos non-embeddable videos from Youtube playlist API


I want to filter out non-embeddable videos from Youtube Playlist API like I do in search API.

I am using videoEmbeddable=true for search api like "https://www.googleapis.com/youtube/v3/search?part=snippet&q=(searchText)&type=video&maxResults=20&videoEmbeddable=true&key=(YTApiKey)" and it's working fine.

But how do I do the same in Playlist API?

"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,status&maxResults=50&playlistId=(id)key=(YTApiKey)".

The param videoEmbeddable=true doesn't seem to work on playlistItems API.

Please help & thanks in advance.


Solution

  • It can be done with some extra steps. As noted, PlaylistItems does not accept that parameter and does not contain the embeddable data in the status part, so we have to make an additional call to Videos:List for it.

    1. Grab all the Video IDs from your call to PlayListItems.
    2. Use them in a call to Videos:List with the part 'status', up to 50 video IDs at a time.

    Example for 3 video IDs:

    GET https://www.googleapis.com/youtube/v3/videos?part=status&id=Ks-_Mh1QhMc%2Cc0KYU2j0TM4%2CeIho2S0ZahI&key={YOUR_API_KEY}
    
    1. Then check each item's status for the embeddable field set to true.

      "status": { "uploadStatus": "processed", "privacyStatus": "public", "license": "youtube", "embeddable": true, "publicStatsViewable": true }