检索"虚荣"频道的Youtube频道信息

10

如果给出一个频道的“自定义网址”(例如youtube.com/wheelockcollege,指向youtube.com/wheelockmarketing1),是否有一种方法可以检索频道详细信息?

我正在使用最新版本的Python包,配合API的新版本3。

1个回答

19

可能需要先使用搜索功能:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&q=wheelockcollege&type=channel&key={YOUR_API_KEY}

然后使用频道ID,您可以获取频道详细信息:

GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UC6ltI41W4P14NShIBHU8z1Q&key={YOUR_API_KEY}

在这种情况下,结果为:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"PsChdkLfsD-u3yuH7KChIH1CRFg/fl8vHBnZ66nKyI7QvfTRQchTAAA\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "id": "UC6ltI41W4P14NShIBHU8z1Q",
   "kind": "youtube#channel",
   "etag": "\"PsChdkLfsD-u3yuH7KChIH1CRFg/zyApGa6dWMliWq5iBE5SL4ewNaQ\"",
   "snippet": {
    "channelId": "UC6ltI41W4P14NShIBHU8z1Q",
    "title": "wheelockmarketing1",
    "description": "Since 1888, Wheelock College has been providing a transformational education to students passionate about making the world a better place—especially for children and families.\n\nWhile most of our students elect to work in the helping professions of education, social work, child life, and juvenile justice and youth advocacy, many pursue—and make exceptional contributions to—a wide variety of professions.\n\nAs a highly respected advocate for social policy, Wheelock also helps to shape and strengthen the social systems that positively impact children and families around the globe.",
    "thumbnails": {
     "default": {
      "url": "https://i3.ytimg.com/i/6ltI41W4P14NShIBHU8z1Q/1.jpg?v=4fdf2807"
     }
    }
   },
   "contentDetails": {
    "relatedPlaylists": {
     "likes": "LL6ltI41W4P14NShIBHU8z1Q",
     "favorites": "FL6ltI41W4P14NShIBHU8z1Q",
     "uploads": "UU6ltI41W4P14NShIBHU8z1Q"
    }
   },
   "statistics": {
    "viewCount": "10354",
    "commentCount": "1",
    "subscriberCount": "43",
    "videoCount": "91"
   }
  }
 ]
}

如果初始搜索返回多个结果,我们就会遇到问题,但我认为这是一个好策略 :)


我已经通过 API 的搜索功能在做这个了,但是正如你所说,多个结果会导致问题。 - Mark Costello
那些“虚荣”的显示名称并不一定是唯一的,因此是有可能返回多个结果的。这只是在搜索非唯一内容时生活中的一个事实。想象一下,如果要根据显示名称搜索Google+用户(或Facebook用户...),“John Smith”可能会返回数千个结果。 - Jeff Posnick
1
从您的评论中,我不明白频道链接如何可能不是唯一的?我确实明白在YouTube上“John Smith”不会返回唯一的结果,但是频道https://www.youtube.com/johnsmith是唯一的。我正在寻找的就是那个特定的频道名称。 - Mark Costello
好的,很公平。频道链接,即URL,将始终唯一标识特定频道。YouTube用户名仍然是许多频道URL的一部分。在v3中,重点是使用唯一的频道ID而不是YouTube用户名,并且Matias提到的搜索方法目前是在YouTube用户名和频道ID之间进行转换的唯一方法。 - Jeff Posnick
1
FYI,我们将这个问题作为我们 YouTube Developers Live 节目的“Stack Overflow 本周问题”进行了介绍:http://www.youtube.com/watch?v=Y-dY3wRDFo8#t=1794s - Jeff Posnick
请注意,Youtube Data API V3仍处于实验性阶段! - mate64

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接