如果频道有自定义 url,如何使用 Youtube 数据 API 获取 Youtube 频道详细信息 [英] How to get Youtube channel details using Youtube data API if channel has custom url

查看:55
本文介绍了如果频道有自定义 url,如何使用 Youtube 数据 API 获取 Youtube 频道详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取具有自定义网址的 YouTube 频道的详细信息,例如 https://www.youtube.com/c/pratiksinhchudasamaisawesome.

I would like to fetch details of a YouTube channel which has a custom URL, like https://www.youtube.com/c/pratiksinhchudasamaisawesome.

自定义频道 URL 遵循以下格式:https://www.youtube.com/c/{custom_channel_name}.

Custom channel URLs follow this format: https://www.youtube.com/c/{custom_channel_name}.

我可以通过频道 ID 和用户名获取 YouTube 频道的详细信息,没有任何问题.不幸的是,我需要使用自定义频道 URL,这是我唯一一次遇到此问题.

I can fetch the details of YouTube channels by Channel ID and username without any issues. Unfortunately, I need to use the custom channel URL which is the only time I encounter this issue.

几个月前我开发了我的应用程序,直到几天前自定义频道 URL 才有效.现在,如果我尝试使用自定义名称获取详细信息,YouTube 数据 API 不会为 YouTube 自定义频道 URL 返回任何内容.

I developed my app few months ago, and the custom channel URL was working up until a few days ago. Now, the YouTube data API does not return anything for the YouTube custom channel URL if I try get details using their custom name.

要获取此频道的详细信息:https://www.youtube.com/user/thenewboston,例如,请求将是:

To get the details of this channel: https://www.youtube.com/user/thenewboston, for example, the request would be:

GET https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=thenewboston&key={YOUR_API_KEY}

回复

200
- SHOW HEADERS -
{
 "kind": "youtube#channelListResponse",
 "etag": "\"zekp1FB4kTkkM-rWc1qIAAt-BWc/8Dz6-vPu69KX3yZxVCT3-M9YWQA\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {

   "kind": "youtube#channel",
   "etag": "\"zekp1FB4kTkkM-rWc1qIAAt-BWc/KlQLDlUPRAmACwKt9V8V2yrOfEg\"",
   "id": "UCJbPGzawDH1njbqV-D5HqKw",
   "snippet": {
    "title": "thenewboston",
    "description": "Tons of sweet computer related tutorials and some other awesome videos too!",
    "publishedAt": "2008-02-04T16:09:31.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/--n5ELY2uT-U/AAAAAAAAAAI/AAAAAAAAAAA/d9JvaIEpstw/s88-c-k-no-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/--n5ELY2uT-U/AAAAAAAAAAI/AAAAAAAAAAA/d9JvaIEpstw/s240-c-k-no-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/--n5ELY2uT-U/AAAAAAAAAAI/AAAAAAAAAAA/d9JvaIEpstw/s240-c-k-no-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "thenewboston",
     "description": "Tons of sweet computer related tutorials and some other awesome videos too!"
    }
   }
  }
 ]
}

效果很好.

现在我们必须获取这些渠道的详细信息:

Now we have to get details of these channels:

然后我们得到:

GET https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=annacavalli&key={YOUR_API_KEY}

回复

200
- SHOW HEADERS -
{
 "kind": "youtube#channelListResponse",
 "etag": "\"zekp1FB4kTkkM-rWc1qIAAt-BWc/TAiG4jjJ-NTZu7gPKn7WGmuaZb8\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 5
 },
 "items": [
 ]
}

使用 API 浏览器.

推荐答案

最简单的解决方案,只使用 API,就是使用 YouTube Data API 的 Search:list 方法.据我所知(请注意,这是我自己的研究,官方文档对此主题没有任何说明!),如果您使用自定义 URL 组件进行搜索,使用频道"结果类型过滤器和相关性"(默认)排序,第一个结果应该就是您要查找的内容.

Simplest solution, using API only, is to just use Search:list method of YouTube Data API. From what I can tell (mind you, this is from my own research, official docs say nothing on this subject!), if you search using the custom URL component, with "channel" result type filter and "relevance" (default) sorting, first result should be what you're looking for.

所以下面的查询得到 16 个结果,第一个是您要查找的结果.我测试过的所有其他自定义频道网址也是如此,所以我认为这是最可靠的方法.

So the following query gets 16 results, with the first one being the one you're looking for. Same goes for all other custom channel URLs I tested, so I think this is the most reliable way of doing this.

GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=annacavalli&type=channel&key={YOUR_API_KEY}

另一个想法是在自定义 URL 上抓取 YouTube 页面,您可以在其中找到 ChannelID 在 HTML 代码的元标记之一中.但这是无效、不可靠和 AFAIK 违反 YouTube 使用条款.

The other idea is just scraping YouTube page at the custom URL, where you can find ChannelID in one of the meta tags in HTML code. But that's ineffective, unreliable and AFAIK in violation of YouTube terms of use.

好吧,它不会为较小的频道返回任何结果,因此它根本不可靠.

Well, it returns no results for smaller channels, so it's not reliable at all.

这篇关于如果频道有自定义 url,如何使用 Youtube 数据 API 获取 Youtube 频道详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆