从给定频道的 YouTube API V3 中提取 viewCount 和 SubscriberCount,其中 channelID 不等于 userID

Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID

我有一长串音乐家需要定期提取社交媒体信息,包括 YouTube。我已经填充了每个音乐家的 "channel name" 如下:

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

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" style URL. Instead Jack U has the following "https://www.youtube.com/channel/UCtuGozGshjqqErhHGEmHnJw”样式。

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

谢谢!

不传递字段 "forUsername" 中的值,而是传递字段中的频道 ID "id"