I'm trying to use the Youtube Analytics API to gather daily view counts for all the videos in my channel. It seems like the video dimension throttles the result at top 10 only. Is there anyway I could get daily view count for all my videos?
1 Answers
At the moment you cannot get metrics for all videos via Analytics API directly. First you need to fetch the ids of all your videos and then request Analytic's data for each. I managed it this way:
- Get the playlist ID for your uploaded videos via Data API https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&maxResults=25&access_token=[TOKEN]. Gives you this result:
{
"kind": "youtube#channelListResponse",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/SAGx1pv6myGXge51dmywGW81h8o\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/g5zJtodBJms3CAfwF_ar2nVgJjU\"",
"id": "[id]",
"contentDetails": {
"relatedPlaylists": {
"likes": "[id]",
"favorites": "[id]",
"uploads": "[id]",
"watchHistory": "[id]",
"watchLater": "[id]"
},
"googlePlusUserId": "[id]"
}
}
]
}
Get all ids of your uploaded videos with the upload playlist id via Data API: https://www.googleapis.com/youtube/v3/playlistItems?part=id&pageToken=&playlistId=[UPLOADID]&maxResults=50&access_token=[TOKEN]. Note: You have to page through the results with nextPageToken.
With the collected video ids you can make a batch request to the Analytics API https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==mine&start-date=2014-12-29&end-date=2015-01-05&metrics=views,likes&dimensions=video,day&filters=video==[videoId],[videoId],[videoId],[...]&sort=video&access_token=[TOKEN] Note: You can batch up to 200 Video Ids.