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

  1. Martijn said on May 10, 2017 at 3:56 am

    Hi, Thanks for het script. Its is realy helpfull. I am an amateur with script writing and I hope someone can help me. I am look for a way tot run this script if I place the videoID in a cel. example: I place the id in cel A1 and the script automaticly runs and puts the info of the video in the cells next to A1. Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

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