You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过YouTube Playlist API筛选排除不可嵌入视频?

How to Filter Embeddable Videos in YouTube PlaylistItems API Requests

Great question! I’ve dealt with this exact limitation before—unlike the Search API, the PlaylistItems API doesn’t offer a direct videoEmbeddable parameter to filter out non-embeddable videos upfront. But there’s a straightforward two-step workaround to get the same result:

Step 1: Fetch all items from the playlist

First, use your existing PlaylistItems API request to pull all the videos in the target playlist. Make sure the part parameter includes snippet (this gives you the resourceId.videoId for each video, which we’ll need next):

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,status&maxResults=50&playlistId=YOUR_PLAYLIST_ID&key=YOUR_API_KEY

If your playlist has more than 50 videos, you’ll need to handle pagination using the pageToken returned in each response until you’ve fetched all items.

Step 2: Batch-check embeddability via the Videos API

Once you have all the videoIds from the playlist, collect them into a comma-separated list and make a single call to the Videos API. Request the status part specifically, as it contains the embeddable boolean field:

https://www.googleapis.com/youtube/v3/videos?part=status&id=VIDEO_ID_1,VIDEO_ID_2,VIDEO_ID_3&key=YOUR_API_KEY

You can include up to 50 video IDs per request, which aligns perfectly with the PlaylistItems API’s maxResults limit—so you can process each page of playlist items in one go.

Step 3: Filter the results

From the Videos API response, iterate through each item and check if status.embeddable is true. These are the videos you can safely embed.

Quick Notes:

  • API Quota Consideration: This adds one extra API call per page of playlist items, but since we’re using batch requests, the quota impact is minimal (the Videos API charges 1 unit per request, regardless of how many video IDs you include).
  • Edge Cases: Some videos might have restricted embeddability in certain regions—if you need to account for that, you can also check the status.embeddable alongside status.regionRestriction in the Videos API response.

内容的提问来源于stack exchange,提问作者udbhateja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:02:22