youtubeyoutube-apiyoutube-data-apiyoutube-analytics-api

How to get metrics from YouTube Analytics API for every video which belongs to current user?


I want to get metrics (such as likes, views and subscribers gained) for every video in my youtube channel (or about 10 latest video) , how can I do it correctly?

I'm using such API call from Youtube Analytics API, but it turns out that it returns total views and total likes from all videos, not individually about every video.

`https://youtubeanalytics.googleapis.com/v2/reports?metrics=views,likes,subscribersGained&ids=channel==MINE&startDate=2014-07-03&endDate=2020-06-01&&key=${apiKey}&access_token=${token}`

I read documentation of YouTube Analytics API and I can't find this information there.


Solution

  • If you want the response to be grouped by video your have to specify the dimension parameter to video.

    Here is a sample request from the documentation (Basic stats/Top 10 – Most watched videos for a channel): https://developers.google.com/youtube/analytics/sample-requests#Channel_Reports

    Although the note does not specify it, the sort parameter must be the first metric that you declared.

    If want to get information on more that 10 videos or to pull information for the latest videos, you can specify the dimension as video and you must specify the video ids in the filter parameter as video==VIDEO1_id,VIDEO2_id....

    The videos in a channel can be retrieved through the YouTube Data API from the search endpoint. You will get a list of videos with their details as a response, among others the videoId and publishedAt values.