Search code examples
youtube-apigdata

Get latest uploads using the v3 version of YouTube gData


Does anyone know how to get the latest uploads for a specific channel (or user will do too)?

In v2 of the gdata api you had the 'http://gdata.youtube.com/feeds/users/[username]/uploads?alt=json' call. But that's deprecated. In v3 there's the youtube.activities.list function, but that doesn't give the same results.

I thought I could get the playlists first, but than I seem to be missing some uploads that are not in a playlist.

Any suggestions?


Solution

  • To get the lastest uploads of a specific channel, don't pass by : youtube.activities.list.

    The YouTube API V3 provide a special playlist of the uploads. To get the id of the playlist two important link :

    https://developers.google.com/youtube/v3/docs/channels/list?hl=fr https://developers.google.com/youtube/v3/docs/playlistItems/list?hl=fr

    And the two steps to get the uploads :

    You need to use youtube.channel.list with the parameters :

    part=contentDetails
    id=ID_OF_THE_CHANNEL
    

    The result is like this :

    {
     "kind": "youtube#channelListResponse",
     "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/CMNDR4CfkeuPx4qnAlqzH11BB5A\"",
     "pageInfo": {
      "totalResults": 1,
      "resultsPerPage": 1
     },
     "items": [
      {
    
       "kind": "youtube#channel",
       "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/MeyW1Z8CbXCFwqPMlOLEwNZyMc0\"",
       "id": "UCzOpxz1sdfp_0eRYqXkoSNA",
       "contentDetails": {
        "relatedPlaylists": {
         "likes": "qsdqsxz1y8np_0eRYqXkoSNA",
         "uploads": "qsdqsd1y8np_0eRYqXkoSNA"
        },
        "googlePlusUserId": "151...45515"
       }
      }
     ]
    }
    

    The playlist id of the uploads : items -> contentDetails -> uploads

    Now you need to call the API a second time with youtube.playlistItems.list with the parameters :

    part=snippet
    playlistId=ID_OF_THE_PLAYLIST_UPLOADS
    

    The result is like this :

    {
     "kind": "youtube#playlistItemListResponse",
     "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/bS4qNeqE0hEI-qb_r8hcbN9G1sE\"",
     "nextPageToken": "CAUQAA",
     "pageInfo": {
      "totalResults": 38,
      "resultsPerPage": 5
     },
     "items": [
      {
    
       "kind": "youtube#playlistItem",
       "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/ItttPAEwALDI0QdLoylbdN6oHcY\"",
       "id": "UUT2INYKRKg8bTaC4Z8-faCKSOt7nfZDHN",
       "snippet": {
        "publishedAt": "2014-08-12T09:45:41.000Z",
        "channelId": "UCM1Bnpxipb8H4GJoITnJ0XQ",
        "title": "Trollsky making a small wood carving knife",
        "description": "Music by Witek Kulczycki\nhttps://itunes.apple.com/pl/album/monaghan-single/id905434557\nhttp://www.cdbaby.com/Artist/WitekKulczycki",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/default.jpg",
          "width": 120,
          "height": 90
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/mqdefault.jpg",
          "width": 320,
          "height": 180
         },
         "high": {
          "url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/hqdefault.jpg",
          "width": 480,
          "height": 360
         },
         "standard": {
          "url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/sddefault.jpg",
          "width": 640,
          "height": 480
         }
        },
        "channelTitle": "Trollskyy",
        "playlistId": "UUM1Bnpxipb8H4GJoITnJ0XQ",
        "position": 0,
        "resourceId": {
         "kind": "youtube#video",
         "videoId": "bTD8U2fcG-Y"
        }
       }
      },
      ...
    

    The uploads are sort by date. Lastest upload is the top of the list.

    Hope it's help !