gpt4 book ai didi

youtube-data-api - 从 channel ID 获取 youtube 用户名

转载 作者:行者123 更新时间:2023-12-04 20:06:26 26 4
gpt4 key购买 nike

如何通过使用 youtube channel ID 获取 channel 的用户名?

例如。 UCnpaBg-u_kHwzuPyaMcyJ0w 是 Sony Max 的 channel ID

现在如何从 Youtube v3 Api 获取用户名“maxindia”

最佳答案

这是一个 Python 解决方案。它试图从视频 ID 中找出 channel 信息。一些较新的 channel 只有 channel ID 而没有用户名。

import requests

API_KEY = "..."

def get_channel_id(vid):
url = "https://www.googleapis.com/youtube/v3/videos?id={vid}&key={api_key}&part=snippet".format(
vid=vid, api_key=API_KEY
)
d = requests.get(url).json()
return d['items'][0]['snippet']['channelId']

def get_channel_title(cid):
url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={cid}&key={api_key}".format(
cid=cid, api_key=API_KEY
)
d = requests.get(url).json()
return d['items'][0]['snippet']['channelTitle']

def main():
video_id = "..."
channel_id = get_channel_id(video_id)
channel_title = get_channel_title(channel_id)
print(channel_id)
print(channel_title)

关于youtube-data-api - 从 channel ID 获取 youtube 用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25383560/

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