Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to retrieve video metrics using Youtube Analytics API

Tags:

youtube-api

According to the Youtube Analytics API documentation (https://developers.google.com/youtube/analytics/v1/available_reports), it looks like you should be able to retrieve metrics for specific videos using the "video" dimension. I am able to get all other metrics successfully - either specifying dimensions like "day" and "country" or supplying no dimension at all.

But when I change the dimensions value to "video", I get a 400 error code with the message "The query is not supported. Check the documentation for supported queries." This is a channel report - not a content owner report - but according to the documentation, this should be a valid report request. I've even tried limiting the result set with a number of extra parameters like start-index, max-results, and sort.

WORKS

client.execute(:api_method => "youtubeAnalytics.reports.query", 
               :parameters => {'ids' => "channel==##USER_ID##",
                               "start-date" => "2012-01-01", "end-date" => "2012-02-01",  
                               "metrics" => "views"})

client.execute(:api_method => "youtubeAnalytics.reports.query",
               :parameters => {'ids' => "channel==##USER_ID##", 
                               "start-date" => "2012-01-01", "end-date" => "2012-02-01", 
                               "metrics" => "views", 
                               "dimensions" => "day"})

DOES NOT WORK - returns 400 error

client.execute(:api_method => "youtubeAnalytics.reports.query", 
               :parameters => {'ids' => "channel==##USER_ID##", 
                               "start-date" => "2012-01-01", "end-date" => "2012-02-01", 
                               "metrics" => "views", 
                               "dimensions" => "video"})

client.execute(:api_method => "youtubeAnalytics.reports.query", 
               :parameters => {'ids' => "channel==##USER_ID##",
                               "start-date" => "2012-01-01", "end-date" => "2012-02-01", 
                               "metrics" => "views", 
                               "dimensions" => "video", 
                               "start-index" => 1, 
                               "max-results" => 5, 
                               "sort" => "views"})

Has anyone been able to make a successful request for a channel report for video level details?

like image 289
Bart Avatar asked Oct 19 '12 21:10

Bart


1 Answers

So the following does work:

channel==USER_ID
start-date=YYYY-MM-DD
end-date=YYYY-MM-DD
metrics=views
dimensions=video
max-results=10
sort=-views

The important thing is that you need to sort by descending views if you want to run a dimensions=video report, and you can only retrieve at most 10 results. This is explained in the second table at

https://developers.google.com/youtube/analytics/v1/available_reports#Channel_Reports

The 10 max results mentioned in their docs, ordered by decreasing views, is obviously an artificial limit imposed by the backend source for Analytics data, but that's all the API could support before. Google just updated it so you can get up to 200 video results - https://developers.google.com/youtube/analytics/revision_history

If you're in a scenario where you want to get Analytics data for arbitrary videos in a given account, not just the 10 with the most views, you need to set the dimension to something other than video, and then run a report with a filter= set to each video id in your account that you're interested in. Again, this might change in the future, but as of right now the Analytics API isn't suited for getting a huge dump of data for every single video in an account in a single API call.

like image 63
Jeff Posnick Avatar answered Oct 20 '22 11:10

Jeff Posnick