gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:39:21 25 4
gpt4 key购买 nike

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

  • [“泰勒 swift ”],
  • [“蕾哈娜”],
  • [“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]

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

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

    谢谢!

    最佳答案

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

    关于python - 从给定 channel 的 YouTube API V3 中提取 viewCount 和 SubscriberCount,其中 channelID 不等于 userID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30713009/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com