如何从频道名称或网址中检索频道

如何从频道名称或网址中检索频道

本文介绍了如何从频道名称或网址中检索频道 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的 v3 API 检索 YouTube 频道的频道 ID.我正在使用 Python 客户端,但似乎没有直接的方法可以找到 YouTube 频道 URL 或名称与其频道 ID 的映射.

I'm trying to retrieve the channel id of a YouTube channel using the new v3 API. I'm using the Python client and it seems that there is no straightforward way to find the mapping of a YouTube channel URL or name to its channel Id.

使用 Python API 客户端时,似乎我必须针对频道名称发出频道"类型的搜索查询,然后遍历每个搜索结果,直到找到匹配项.

Using the Python API client, it seems that I have to issue a search query of type 'channel' for the channel name, then iterate through each search result until I find a match.

我将以 http://youtube.com/atgoogletalks 频道为例>

I'm going to use the http://youtube.com/atgoogletalks channel as an example

search_channel_name = 'atgoogletalks'     #Parsed from http://youtube.com/atgoogletalks
search_response = youtube.search().list(
    type='channel',
    part='id,snippet',
    q=search_channel_name,
    maxResults=50
    ).execute()
for sri in search_response["items"]:
    channels_response = youtube.channels().list(
        id=sri["id"]["channelId"],
        part="id, snippet, statistics, contentDetails, topicDetails"
        ).execute()

    for cr in channels_response["items"]:
        channelname = cr["snippet"]["title"]
        if channelname.lower() == search_channel_name:
            return 'Success'

我翻阅了文档,寻找一种更直接的方法,结果很简短.有更容易的方法吗?如果没有,是否有计划将此功能添加到 API 中?

I've crawled the documentation looking for one a more straightforward way of doing this and come up short. Is there an easier way? If not, is there a plan to add this functionality to the API?

推荐答案

Following YouTube 数据 API你可以使用 forUsername 的 youtube.channels.list() 参数

Following YouTube Data APIyou could use forUsername parameter of youtube.channels.list()

使用您自己的示例:

search_channel_name = 'atgoogletalks'
channels_response = youtube.channels().list(
        forUsername=search_channel_name,
        part="id, snippet, statistics, contentDetails, topicDetails"
).execute()

这篇关于如何从频道名称或网址中检索频道 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:16