0

I am currently using the YouTube Data Channel API, which allows me to retrieve the Channel ID of any given username.

https://www.googleapis.com/youtube/v3/channels?key={KEY HERE}&forUsername={USERNAME}&part=id,snippet&order=date

It works for the majority of usernames, but for some reason it chooses not to work for others.

For example, if you visit the URL: https://youtube.com/impaulsive, we can see that the username must be impaulsive.

However, if you search that through the Channel API via the forUsername attribute, it returns no results - even though it is their actual username and directs you to their official channel.

Is there a way to retrieve the Channel ID from a username?

DaImTo
  • 88,623
  • 26
  • 153
  • 389
  • Please update your question or else add comments under my answer below if needing further help (and/or clarifications). – stvar Jan 13 '21 at 20:17

1 Answers1

1

Your issue is very much recurrent with YouTube Data API (here, on SO was recently tackled several times: just issue the following SO search query: [youtube-data-api] forUsername).

Basically, you have to acknowledge two things:

  1. User names are a legacy feature of the API v3; not every channel has one attached; no channel is required to have one attached. (See this official statement from Google staff from 2013-07-11.)

  2. If you come across URLs of form https://www.youtube.com/c/NAME (or even https://www.youtube.com/NAME), then NAME is not necessarily (though it could be) the YouTube user name of an YouTube channel. NAME is a channel's custom URL, a different category. (See this official account from Google support.)

Your example -- impaulsive -- fits well with point 2 above, because it is the custom URL of the channel of which ID is UCGeBogGDZ9W3dsGx-mWQGJA, yet is not the user name of any channel:

$ python3 youtube-search.py --custom-url impaulsive
UCGeBogGDZ9W3dsGx-mWQGJA

$ python3 youtube-search.py --user-name impaulsive
youtube-search.py: error: user name "impaulsive": no associated channel found

The script youtube-search.py used above is a public (MIT licensed) Python 3 program (that I developed) implementing an algorithm that searches for custom URLs and also is querying the API for user names.

Note that youtube-search.py requires a valid API key to be passed to it as argument of the command line option --app-key or, otherwise, passed on as the environment variable YOUTUBE_DATA_APP_KEY. (Use the command line option --help for brief helping info.)

stvar
  • 5,871
  • 2
  • 10
  • 23