按作者搜索 YouTube 视频 [英] Search YouTube videos by author

查看:51
本文介绍了按作者搜索 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 YouTube API 3.0,想按作者搜索视频.我将如何做到这一点?

I'm using YouTube API 3.0 and would like to search for videos by author. How would I accomplish this?

我正在使用 python 客户端库.

I am using python client library.

推荐答案

在 YouTube Data API v3 中,您需要从用户的频道中找到 UploadsPlaylist,然后他们会查找该频道的 PlaylistItems.

In the YouTube Data API v3, you need to find the UploadsPlaylist from the user's channel, and they lookup the PlaylistItems for that channel.

例如,如果您想查找 GoogleDevelopers 上传的内容,请先找到他们的 channel_id.

So for example, if you wanted to find the GoogleDevelopers uploads, first find their channel_id.

如果您不知道用户的 channel_id,则必须调用搜索资源(将 kind 设置为channel")才能找到它:

If you don't know a user's channel_id, you must make a call to the Search resource (with kind set to 'channel') to find it:

https://www.googleapis.com/youtube/v3/search?part=id&maxResults=1&q=GoogleDevelopers&type=channel&key={YOUR_API_KEY}

返回:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"Sja0zsjNVqBAv0D_Jpz6t1GyTzk/fm4P2RLxOAO0xdASI5BagD86H8A\"",
 "pageInfo": {
  "totalResults": 21,
  "resultsPerPage": 1
 },
 "nextPageToken": "CAEQAA",
 "items": [
  {
   "id": {
    "kind": "youtube#channel",
    "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
   },
   "kind": "youtube#searchResult",
   "etag": "\"Sja0zsjNVqBAv0D_Jpz6t1GyTzk/q4hYefapiMoagc7b_3bYaVZvSJo\""
  }
 ]
}

如您所见,他们的 channelId = UC_x5XG1OV2P6uZZ5FSM9Ttw

As you can see, their channelId = UC_x5XG1OV2P6uZZ5FSM9Ttw

调用频道资源的 contentDetais 部分以查找其上传的播放列表:

Make a call to the contentDetais part of the Channel resource to find their Uploads Playlist:

https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UC_x5XG1OV2P6uZZ5FSM9Ttw&key={YOUR_API_KEY}

哪个会返回这个:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"Sja0zsjNVqBAv0D_Jpz6t1GyTzk/ZouMU1qBRkF6DgacOLHE88Xk144\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "id": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
   "kind": "youtube#channel",
   "etag": "\"Sja0zsjNVqBAv0D_Jpz6t1GyTzk/khrrkvk8Tl0XWRZoN66zqloSJM4\"",
   "contentDetails": {
    "relatedPlaylists": {
     "uploads": "UU_x5XG1OV2P6uZZ5FSM9Ttw"
    }
   }
  }
 ]
}

如您所见,他们上传的播放列表 ID 为 UU_x5XG1OV2P6uZZ5FSM9Ttw

As you can see, their uploads playlist id is UU_x5XG1OV2P6uZZ5FSM9Ttw

调用 PlaylistItems 资源以获取由 GoogleDevelopers 上传的视频:

Make a call to the PlaylistItems resource to get videos uploaded by GoogleDevelopers:

https://www.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet%2CcontentDetails&playlistId=UU_x5XG1OV2P6uZZ5FSM9Ttw&key={YOUR_API_KEY}

这篇关于按作者搜索 YouTube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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