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
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.