【问题标题】:Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID从给定频道的 YouTube API V3 中提取 viewCount 和 SubscriberCount,其中 channelID 不等于 userID
【发布时间】:2015-06-08 15:17:53
【问题描述】:

我有一长串需要定期提取社交媒体信息的音乐家,包括 YouTube。我将每个音乐家的“频道名称”填充如下:

  • [“泰勒斯威夫特”],
  • [“蕾哈娜”],
  • [“SiaVEVO”],
  • [“AlessoOfficialVEVO”],

要提取信息,我使用以下代码:

for item in list:
yt_user=item[0]
youtube='https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername='+str(yt_user)+'&key=***key***'
youtube2 = urllib2.urlopen(youtube)
tube = json.load(youtube2)
a=str(tube['items'][0]['statistics']['viewCount'])
b=str(tube['items'][0]['statistics']['subscriberCount'])  
out=[a,b]

但是,某些音乐家频道页面没有“https://www.youtube.com/user/RihannaVEVO”样式的 URL。相反,Jack U 具有以下“https://www.youtube.com/channel/UCtuGozGshjqqErhHGEmHnJw”样式。

抱歉,如果我错过了一些非常简单的事情,但是当没有用户名而只有一个 channelId 时,我找不到任何方法来更改 Channels.List API 调用。

谢谢!

【问题讨论】:

    标签: python youtube youtube-data-api


    【解决方案1】:

    而不是在“forUsername”字段中传递值,而是在“id”字段中传递频道ID

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 2014-04-10
      • 2018-10-16
      • 2015-03-11
      • 2023-03-31
      • 2023-04-03
      • 2015-09-16
      • 2017-11-21
      • 1970-01-01
      相关资源
      最近更新 更多