YouTube API to Google Spreadsheets

Because I love Alan. Here’s the API version in Google Script to grab YouTube stats. It does a bit more than the previous XPath version and you can set it to be triggered repeatedly. I’m going to add a loop to add multiple videos etc. in the near future but it’s a good start for anyone who’s doing research on stuff like this.

It is funny what you might notice when you can see the data like this. I triggered it manually twice just to get a few lines in there. Notice that between the first two entries there are no additional views but a chunk more likes/dislikes. Makes me wonder if people are just weighing in without watching or if the data are collected differently resulting in some delay.

Here’s the script1 and it’s pretty well commented up. You’ll need an API key. 🙂

You do see some weird stuff in the raw JSON. Like there’s a Favorites field. Does that exist in YouTube? I didn’t really think about it until it came up 0 for every video . . . even Gangnam Style.

Here’s the result running every hour on a video that I’m hoping changes a bit. I got it off the trending page so it has to be cool right?


1 It took me a good while to realize I need to do the [0] piece to navigate the first element. My best friend is Logger.log(yourVariable) in Google Script. When I finally got methodical enough and used it to spit out the variable results at each level, I was able to figure it out.

Comments on this post

No comments.

Leave a Reply

Trackbacks and Pingbacks on this post

  1. […] Although the following code is my own implementation, I used the examples found at the Bionic Teaching blog as a jumping off point. […]

TrackBack URL