使用v3版本的YouTube gData获取最新上传内容

时间:2014-09-06 16:19:58

标签: youtube-api gdata

有谁知道如何获取特定频道的最新上传(或者用户也会这样做)?

在gdata api的v2中,你得到了' http://gdata.youtube.com/feeds/users/[username]/uploads?alt=json'呼叫。但这已被弃用了。在v3中有youtube.activities.list函数,但这并没有给出相同的结果。

我以为我可以先获取播放列表,但我似乎错过了一些不在播放列表中的上传内容。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

要获得特定频道的最新上传内容,请不要通过:youtube.activities.list

YouTube API V3提供上传的特殊播放列表。 要获取播放列表的ID两个重要链接:

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

获取上传的两个步骤:

您需要将youtube.channel.list与参数一起使用:

part=contentDetails
id=ID_OF_THE_CHANNEL

结果如下:

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

上传的播放列表ID:items -> contentDetails -> uploads

现在您需要使用youtube.playlistItems.list第二次使用参数:

调用API
part=snippet
playlistId=ID_OF_THE_PLAYLIST_UPLOADS

结果如下:

{
 "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"
    }
   }
  },
  ...

上传按日期排序。最快的上传是列表的首位。

希望它有所帮助!