The YouTube Data API allows us to query data about a channel using the channel id or the channel username.
I thought that a channel's username would be its "@handle" as listed below the channel title and (commonly) in the channel URL. But 3Blue1Brown is a clear counterexample to this.
from googleapiclient.discovery import build
# Instantiate a googleapiclient.discovery.Resource object for youtube
youtube = build(
serviceName='youtube',
version='v3',
developerKey='MYKEY'
)
# Define the request
request = youtube.channels().list(
part="contentDetails",
forUsername="3blue1brown"
)
# Execute the request and save the response
response = request.execute()
response
# {'kind': 'youtube#channelListResponse',
# 'etag': 'RuuXzTIr0OoDqI4S0RU6n4FqKEM',
# 'pageInfo': {'totalResults': 0, 'resultsPerPage': 5}}
I know I can just use the channel's id instead, but the id is becoming harder to find and frankly, it just bothers me that I don't know how to find a channel's username.