关于YouTube DataAPI片尾(Endscreen)与卡片(Cards)功能的技术咨询
Let's tackle your two core requirements step by step, based on what's available with official YouTube APIs:
1. Querying Videos with Endscreen/Cards & Their Linked Content
To pull data on which videos have Endscreen or Cards enabled, plus the linked videos within them, you'll use the YouTube Data API v3 with specific request parameters:
- Base API Endpoint:
GET https://www.googleapis.com/youtube/v3/videos - Required Parameters:
part=contentDetails(this includes both Endscreen and Cards metadata)key=YOUR_API_KEY(your valid API key from Google Cloud Console)id(comma-separated list of video IDs you want to check; or usemyRecentUploadsas theidvalue to fetch your own channel's videos)
Extracting Endscreen Data
In the API response, look for the contentDetails.endScreen object. Each entry in this array will include:
type: The type of Endscreen element (e.g.,video,playlist)videoId/playlistId: The ID of the linked content
Extracting Cards Data
For Cards, check the contentDetails.card object in the response. This will contain:
cardType: The type of card (e.g.,video,playlist,channel)linkedEntityId: The ID of the video/playlist/channel linked in the card
If you need to batch-check all videos on your channel, first use the search.list endpoint to fetch all your video IDs, then pass those IDs to the videos.list request.
2. Updating Endscreen & Cards via API
Unfortunately, this is where things get tricky—there are no public, official API endpoints to update Endscreen or Cards directly as of now:
- Endscreen Updates: The YouTube Data API v3 doesn't expose any methods to create or modify Endscreen elements. You'll have to use the YouTube Studio web UI or mobile app for this task.
- Cards Updates: The old Annotations API (which was used for similar functionality) has been deprecated, and there's no replacement public API for Cards. While some developers have tried modifying
contentDetailsfields viavideos.update, this is unsupported and may break or stop working without warning.
Alternative (Restricted) Option
If you're part of a YouTube Partner Program or MCN, you can apply for access to the YouTube Creator Studio API, which does include methods for managing Endscreen and Cards at scale. But this API is not open to all developers—you'll need to go through Google's application process.
Important note: Automating UI interactions (like using Selenium to click through YouTube Studio) violates YouTube's Terms of Service, so this is not a recommended approach.
内容的提问来源于stack exchange,提问作者MathsTeacher.blog

