Fetch and process YouTube view counts in Go
Programming Snapshot – Go YouTube Stats
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.
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.
To quickly generate an API key, select a key type from the Credentials menu (Figure 3). Once created (Figure 4), the API key opens a treasure trove of all kinds of public data across Google's offerings. To mitigate the impact of potential misuse with stolen keys, the recommended approach is to restrict the validity of any keys you generate to the areas you actually need – in this case, to the YouTube Data API (Figure 5). You can do this by drilling down on the Restrict API Key option displayed next to the new key.
[...]
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.