Skip to content Skip to sidebar Skip to footer

Youtube Api Subscriber Count Incorrect Because Of Channels With The Same Name

Code: import requests import json key = 'key' #api key url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&key='+ key +'&forUsername=' youtuber = input(

Solution 1:

You have to acknowledge the following peculiarity of YouTube site: it permits (by design) that the very same name -- in your case Markiplier -- to be a channel's custom URL and, at the same time, to be the (legacy) user name of another channel.

Please read the first few paragraphs of my answer to a very much related question. From there, you'll get a pretty good idea about the difference between the two (sometimes confusing) concepts: channel user name and channel custom URL.

Concretely, if you'll make use of my Python3 public script youtube-search.py, you'll see that there are two different channels that exhibit the behavior I just described w.r.t. the name Markiplier:

$ python3 youtube-search.py --user-name Markiplier
UCxubOASK0482qC5psq89MsQ

$ python3 youtube-search.py --custom-url Markiplier
UC7_YxT-KID8kRbqZo7MyscQ

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.)

A further Channels.list API endpoint query on the following URL:

https://www.googleapis.com/youtube/v3/channels?id=UCxubOASK0482qC5psq89MsQ,UC7_YxT-KID8kRbqZo7MyscQ&part=id,snippet,statistics&fields=items(id,snippet(title,description,customUrl),statistics(subscriberCount))&maxResults=2&key=...

will confirm the difference you've experienced:

{"items":[{"id":"UCxubOASK0482qC5psq89MsQ","snippet":{"title":"markiplier","description":"I will no longer be updating this channel! All my new videos with be uploaded to markiplierGAME! Please re-subscribe on that channel to stay up-to-date on my videos!"},"statistics":{"subscriberCount":"85000"}},{"id":"UC7_YxT-KID8kRbqZo7MyscQ","snippet":{"title":"Markiplier","description":"Welcome to Markiplier! Here you'll find some hilarious gaming videos, original comedy sketches, animated parodies, and other bits of entertainment! If this sounds like your kind of channel then please Subscribe Today!\n\nTotal Charity Raised ▶ $3,000,000+","customUrl":"markiplier"},"statistics":{"subscriberCount":"27800000"}}]}

Now, to make a summary of my points w.r.t. your question -- I run into the unfortunate issue of channels with the same name. How do I prevent this? --, I note the following:

  1. Be sure what is that you look to obtain from the API: custom URLs and user names are different API concepts.
  2. If you're trying to obtain info about a channel for which you have its user name, then use Channel.list endpoint queried with an appropriate forUsername parameter.
  3. If you're trying to obtain info about a channel of given custom URL, then use the procedure and Python code I described in my answer to this question Obtaining a channel id from a youtube.com/c/xxxx link. Also be prepared for possible failure of that procedure (due to way the API is currently implemented, it may well happen that the procedure fails on certain valid custom URLs).

Post a Comment for "Youtube Api Subscriber Count Incorrect Because Of Channels With The Same Name"