0

YouTube Developers Live: Troubleshooting the YouTube Analytics API


JEFF POSNICK: Hey, everybody. This is Jeff Posnick coming
to you from New York City, and welcome to this week’s
episode of YouTube Developer’s Live. This week we’re
going to be talking about how to debug issues
that you might be having when trying to craft your YouTube
Analytics API reports. This is something that we’ve
seen a number of developers have a little bit
of confusion about, and while following
the documentation should get you where
you need to go, we wanted to provide a little
bit of extra hints and tips for folks who might be
running into issues. So let’s dive in right now by
pulling up a copy of my screen, and I’ll show you what
we’re talking about. So right now, we have the
YouTube Analytics API explorer open right now, and
this is a great way of being able to
run sample queries. I highly recommend that
folks try this out, and we’ll have a little
annotation pointing to it, before you actually write
code that uses analytics API. Because you can try out
all the different parameter combinations, it’ll take you
through the OAuth 2.0 flow, and it will allow you to just
see which parameters work and which don’t work
in a real time fashion. So we’re going to be using this
for all our debugging today. And another really
useful resource I’m going to pull
open right here is something from our
documentation, which is a list of all the
supported parameters for the different
types of reports. And it’s kind of
like– I don’t want to say it’s a matrix
or anything like that, but it kind of does
give you the list of the different dimensions
that are supported, and given those
dimensions, these are the metrics
that are supported. A real nice break down there. So we’re going to
walk through how to interpret those pieces
of information that are in the docs. And finally, there’s
this other page, which has some kind of
pre-defined requests that are known to work. So these are the
exact combinations of parameters that you could
use for specific common queries. And kind of think of this
as a cookbook you could use with guaranteed things
that work for doing things like getting country
specific view counts or daily watched time metrics
[? versus ?] channels videos, things like that. So let’s jump back
though, and we’re going into the API Explorer. The first source of confusion
that we see for a lot of folks is that they don’t
really know how to populate the value over
here for the IDs parameter. If you’re running a
channel level report, which most folks will be
doing, you do need to know a piece of information
that most people don’t know off the top their head. And that’s your
YouTube channel ID. There are a couple of different
ways of getting that channel ID, and the easiest way and
the way that I’m going to go through right now, it’s
just using a special page on YouTube.com, which is
YouTube.com/accounts_advanced. And this page gives you
some advanced information about your channel, including
your YouTube channel ID. There are definitely
ways of looking this up via the API to get the
general idea of the currently authenticated user. You can do a
YouTube.channels.list API call with the mine
equals 2 parameter set. We have lots of code samples in
our documentation showing that, but this is just a really
easy way using the docs to pull it up right here. So I’m logged into a
test account right now. I’m going to copy
that, and I’m going to put in the channel equals
equals and that value. There’s an extra space right
there, I’m going to get rid of. So that part’s good. The start date and end
date to record parameters– that one, fortunately, a
little bit harder to mess up. You just need to do the
format of a four digit year, a two digit
month, two digit day. I’m going to do a report that
spans the entire year of 2012. And now, we’re
getting into things that vary from report to report. I’m going to show you how to
do a very simple report, which is to get the total
number of views aggregated by video for that given year. So I’m going to
refer back to this– I’m sorry, this
matrix right here. And the dimension I’m
interested in is a video. So I’m looking up in this
list of supported values, and dimension video, I can
get these different metrics. So I want views, in
that particular case, and that’s great. And let’s just start with that,
let’s just say I naively think, OK, metrics– sorry, metrics
views and dimensions video. OK, I’m done, right? And I’m just going to go
down here, click Execute, and I get back the
dreaded 400 bad request. So that’s actually not
a report that will work. And if I go over
here, this pulls up that same page I was on. We do give you a handy
URL that you could visit. So what went wrong? The problem is
actually that you need to have a sort restriction
and a max results restriction. So these two columns over here
are actually quite important. It’s not just like optional
values that you need to use. You actually do– you need
to put in one of these sort restrictions and
you need to request 10 or fewer videos
in the results. And this is just due to
some back end limitations on the YouTube Analytics
API infrastructure. So we do spell that over
here, but this is something that a lot of people
have trouble with. So we’re going to put in
sort by decreasing views. This minus right in front of
the views is really important. It means that we’re sorting
by decreasing views, and we need to put 10 or
fewer for the max results. So let’s go back up here. We have max results within 10
and sorts by decreasing views. Click Execute again,
and lo and behold, get back some metrics for my
very unpopular test channel. So this shows you
that you really do need to be careful about
what the required parameters are over here, and if
you’re not sure, go into this cookbook page and
seeing all these combination parameters that are
guaranteed to work for specific types of reports,
is a really useful thing to do. So that’s actually all
I wanted to cover today. Thanks so much for joining
us, and hopefully, this help you get started with
the YouTube Analytics API. Bye, everybody.

Bernard Jenkins

Leave a Reply

Your email address will not be published. Required fields are marked *