Search YouTube videos by author [closed]

2019-04-14 04:32发布

问题:

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

I am using python client library.

回答1:

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.

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

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}

Returns:

{
 "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\""
  }
 ]
}

As you can see, their channelId = UC_x5XG1OV2P6uZZ5FSM9Ttw

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}

Which will return this:

{
 "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"
    }
   }
  }
 ]
}

As you can see, their uploads playlist id is UU_x5XG1OV2P6uZZ5FSM9Ttw

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}