Fetch and process YouTube view counts in Go
Programming Snapshot – Go YouTube Stats

Lead Image © Erik Reis, 123RF.com
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
-
Plasma 6.3 Now Available
Plasma desktop v6.3 has a couple of pretty nifty tricks up its sleeve.
-
LibreOffice 25.2 Has Arrived
If you've been hoping for a release that offers more UI customizations, you're in for a treat.
-
TuxCare Has a Big AlmaLinux 9 Announcement in Store
TuxCare announced it has successfully completed a Security Technical Implementation Guide for AlmaLinux OS 9.
-
First Release Candidate for Linux Kernel 6.14 Now Available
Linus Torvalds has officially released the first release candidate for kernel 6.14 and it includes over 500,000 lines of modified code, making for a small release.
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.