如何在YouTube Analytics API请求中添加视频维度获取视频级流量数据
Adding Video Dimension to YouTube Analytics API Request for Video-Level Traffic Source Data
Got it, let's adjust your existing API call to pull video-level traffic source metrics easily. Here's the modified request you can use:
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==[ChannelID]&start-date=[STARTDATE]&end-date=[ENDDATE]&metrics=views,estimatedMinutesWatched&dimensions=day,insightTrafficSourceType,video&filters=country==US&include-historical-channel-data=true&max-results=10000
Key Changes & Notes:
- Added
videoto thedimensionsparameter: This is the core tweak—by includingvideoalongsidedayandinsightTrafficSourceType, the API will break down metrics per individual video, per day, per traffic source. - Increased
max-resultsto 10000: Video-level data generates far more rows than channel-level, so bumping this up (the maximum allowed value is 10000) helps avoid truncating results. If you need more than 10000 rows, you'll have to implement pagination using thenextPageTokenfrom the response. - Permissions Check: Ensure your OAuth 2.0 token has the
youtubeAnalytics.readonlyscope (and optionallyyoutube.readonlyif you want to map video IDs to titles later)—this is required to access video-level analytics data. - Data Output: The response will now include a
videocolumn with the video ID, letting you correlate each row's views and watch time to a specific video, its traffic source, and the day it was recorded.
If you run into issues like dimension/metric incompatibility (though this combination is valid per YouTube Analytics specs), double-check that your date range doesn't include videos that might have been removed, or verify your channel ID is formatted correctly.
内容的提问来源于stack exchange,提问作者R P
相关产品推荐
相关产品推荐

