ryoutube-analytics-apiyoutube-analytics

Is there a Next Page Token in the YouTube Analytics API


I'm hoping to get analytics on all videos on my YouTube Channel. I have the following code:

baseURL <- "https://youtubeanalytics.googleapis.com/v2/reports?dimensions=video&endDate=2021-05-25&ids=channel%3D%3DMINE&maxResults=200&metrics=views%2CaverageViewDuration%2Ccomments%2Cdislikes%2CestimatedMinutesWatched%2Clikes%2Cshares&sort=-views&startDate=2000-01-01"

temp <- GET(baseURL, myToken)

And this returns 200 videos worth of analytics, which is great, but I'd like to get all videos (around 5,000) instead of 200. I've used a Next Page Token in the YouTube Data API, but didn't find one in analytics. Is this possible? If not, what is a good way to go about doing this?


Solution

  • Yes, there is. You will have to loop through the max results at a rate of 50 per page (50 is the upper limit) and dynamically grab the "nextPageToken". Each token represents a different page of 50 results. I have inputted the page token to get to page 2. In your code, you will have to dynamically do this to get all videos from all pages. To anyone wondering, the main benefit of this method over just using the Youtube Data API is that you can grab Private Videos (i.e. Not Public).

    enter image description here