Skip to content

YouTube Data API

Austin Cullar edited this page Oct 11, 2024 · 6 revisions

Overview

Astro utilizes the YouTube Data API for data collection. In order to use the API, you need to create an API key.

Creating a YouTube API key

The steps I used are:

  1. Login to Google Developers Console.
  2. Create a new project.
  3. On the new project dashboard, click Enable APIs and Services.
Screenshot 2024-09-27 at 10 59 05 PM
  1. In the library, navigate to YouTube Data API v3 under YouTube APIs.
Screenshot 2024-09-27 at 11 04 11 PM Screenshot 2024-09-27 at 11 06 01 PM
  1. Click the YouTube Data API v3 tile, and enable the API on the next screen.
  2. Create credentials.
Screenshot 2024-09-27 at 11 08 44 PM
  1. A screen will appear with the API key.

API Quirks

Helpful information about the API.

Quotas

The YouTube Data API works on a quota system, restricting API usage for each user per 24 hour period in order to protect service quality. In a 24 hour period, an API user is not allowed 10,000 quotas. Each API call has a different quota cost, which can be viewed here. Astro is currently only performing read (or 'list') operations, which are the cheapest API calls, costing just 1 quota each. Therefore, it is unlikely that data collection with Astro with ever meet/exceed this quota limit.

Comment count

The commentCount field returned in the API response for video metadata is not always accurate.

I noticed this while working on adding a progress bar for downloading comments from a video, since I was planning to use the comment count as the 'width' or 'step count' of the progress bar (250 comments = 250 steps on the progress bar, reading 50 comments means advancing the progress bar 50 steps). When running some tests against a video with 336 comments, I noticed that my code would download 330 and then stop, leaving my progress bar to wait infinitely without completing. Thinking this was a bug in my code, I checked the dataframe constructed from the comment data, and it reflected 330.

Some online reading indicated that this may be because the mysterious 6 missing comments had some kind of moderative action taken against them. This could include:

  • Filtering rules
    • The video's author has filtering rules in place which block comments containing certain words/strings. When these comments get filtered out, then become invisible to every other user besides the comment author.
  • YouTube moderation
    • The comment was detected/flagged by YouTube's automated moderation service, restricting visibility of the comment.
    • If the video's author has blocked the user attempting to comment, it seems said comment would still be included in the overall count, but its visibility is restricted.
Clone this wiki locally