由于频道名称相同,YouTube API订阅者计数不正确 [英] YouTube API subscriber count incorrect because of channels with the same name

查看:61
本文介绍了由于频道名称相同,YouTube API订阅者计数不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

import requests
import json

key = 'key' #api key
url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&key='+ key +'&forUsername='

youtuber = input('What\'s the name of the youtuber: ') #get youtuber name
url += youtuber.lower() #youtuber name all lowercase

r = requests.get(url) #get data from youtuber channel webpage

try:
    subs = json.loads(r.text)['items'][0]['statistics']['subscriberCount']
except:
    print('Your youtuber doesn\'t exist ):')
    exit()
print(youtuber,"has",subs,"subscribers! Woohoo!")

没关系:

输入:Google

输出:Google有9640000个订阅者!呜呼!

Output: Google has 9640000 subscribers! Woohoo!

这不是不是:

输入:Markiplier

Input: Markiplier

输出:Markiplier有84900位订阅者!oo!(实际上,他的主要频道有2780万订户)

Output: Markiplier has 84900 subscribers! Woohoo! (Actually, his main channel has 27.8M subscribers)

我不幸遇到了同名频道.我该如何预防?

I run into the unfortunate issue of channels with the same name. How do I prevent this?

推荐答案

您必须承认YouTube网站的以下特殊性:它允许(通过设计)名称相同-在您的情况下为 Markiplier -是一个频道的自定义URL,同时也是另一个频道的(旧版)用户名.

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.

具体来说,如果您要使用我的Python3公共脚本 youtube-search.py ,您会看到有两种不同的渠道表现出我刚才描述的行为名称 Markiplier :

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

请注意, youtube-search.py​​ 需要将有效的API密钥作为命令行选项-app-key 的参数传递给它,否则,作为环境变量 YOUTUBE_DATA_APP_KEY 传递.(使用命令行选项-help 可获得简短的帮助信息.)

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

进一步的 Channels.list 在以下URL上进行API端点查询:

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,代码段,统计信息和字段=项目(id,代码段(标题,说明,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. 请确保您希望从API中获得什么:自定义URL 用户名是不同的API概念.
  2. 如果您要获取有关拥有其用户名的频道的信息,请使用通过适当的 forUsername查询的 Channel.list 端点参数.
  3. 如果您要获取有关给定自定义URL 频道的信息,请使用我在对此问题的回答
  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).

这篇关于由于频道名称相同,YouTube API订阅者计数不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆