Fetch and process YouTube view counts in Go

Programming Snapshot – Go YouTube Stats

Lead Image © Erik Reis, 123RF.com

Lead Image © Erik Reis, 123RF.com

Article from Issue 280/2024
Author(s):

To keep track of how well his YouTube videos are performing, Mike Schilli writes a Go program that uses Google's YouTube Data API to query the stats and then visualizes the results.

In my continuing quest to become immortal, I've been maintaining a YouTube channel that displays newly produced videos on an ongoing basis (Figure 1). I figured that it would be interesting to see which of my productions did best: the home cooking videos, those dealing with car repair tasks, or even those dissecting and modding all kinds of electronic gadgets. Sure, YouTube provides basic stats in its Studio section, but because I like writing my own code with custom features, I thought it'd be interesting to see how to fetch YouTube stats with Go and process and visualize the data this month.

Figure 1: Mike Schilli's personal YouTube channel.

Register Before You Try

Before granting your homegrown applications access to the viewer metadata, however, YouTube owner Google requires you to register a project [1] to use their API. The idea here is to keep an eye on bot activities and, where needed, to restrict them by imposing a quota. Google distinguishes here between two different mechanisms for authenticating incoming API requests. If requests read private user data or even want to write to the server on behalf of the user, OAuth credentials are required. But if you just want to read data that is already publicly available (e.g., the number of views for a video), all you need is an API key for a project that uses the YouTube Data API (Figure 2), which you can quickly register on the Google Console.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Give, Don't Take

    Go makes it easy to bundle universal code into a package and share it with the world on GitHub. Mike Schilli explains the tricks and how to avoid the pitfalls.

  • YouTube Players

    YouTube offers more than just funny kitten movies; you will also find more than 60 million music videos. With a native YouTube client for Linux, you can use this online jukebox as conveniently as your local music collection.

  • Tube Archivist

    Tube Archivist indexes videos or entire channels from YouTube in order to download them with the help of the yt-dlp tool.

  • Programmatically change YouTube metadata

    Instead of manually editing the metadata of YouTube movies, video craftsman Mike Schilli dips into YouTube’s API spell book and lets a script automatically do the work.

  • Flashing and programming an LED display

    Mike Schilli recently ordered a low-budget LED display and is all set to customize the firmware and add some homemade scripts.

comments powered by Disqus