3

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.

inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
Ibrahim
  • 267
  • 1
  • 6
  • 18
  • i was exploring the API v3 but couldn't find author query parameter either in search or videos API. But v2 has author parameter in videos API. https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters https://developers.google.com/youtube/v3/docs/videos/list – Ibrahim Feb 07 '13 at 20:47
  • You might want to post what you're doing in API2 so that we have a better idea of what you're trying to do. Also, if you post more information about the overall problem that you are trying to solve, we might be able to avoid any [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)s – inspectorG4dget Feb 07 '13 at 21:06
  • see http://stackoverflow.com/questions/3857917/python-search-playlists-on-youtube – Rachel Gallen Feb 07 '13 at 21:10
  • Overall problem is ..i want to output a list of all videos uploaded by a particular author using youtube api v3. how would i accomplish this? – Ibrahim Feb 07 '13 at 21:15
  • An author is just called a channel now, and every channel has an uploads playlist. You just need to find the videos in that uploads playlist. See my answer below. – Matt Koskela Feb 07 '13 at 21:29

1 Answers1

5

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}

Matt Koskela
  • 5,269
  • 3
  • 26
  • 29
  • matt, thanks for the detailed reply. But i have small concern here, that you are passing q=GoogleDevelopers, and this means search all channels. and if we increase the max results https://www.googleapis.com/youtube/v3/search?part=id&maxResults=10&q=GoogleDevelopers&type=channel&key={YOUR_API_KEY} it shows us more results – Ibrahim Feb 08 '13 at 15:46
  • 2
    I spoke with a number of Google employees about this last week and they assured me that this was the best way to get a channel's ID from their username. It seems a little strange to me too, but they told me if your query directly matches a channel's username, it will always be the first result. I just wish it was documented.. – Matt Koskela Feb 08 '13 at 18:06
  • You can always use the v2 user feed to find it too, which is what I was doing until I found out about the v3 search entity. You just have to parse it out of the xml: http://gdata.youtube.com/feeds/api/users/googleDevelopers?v=2 – Matt Koskela Feb 08 '13 at 18:10
  • Thanks Matt for the kind reply. – Ibrahim Feb 08 '13 at 18:26