为 YouTube 用户检索提要(上传)

Retrieving feeds (uploads) for YouTube user

去年有时我可以通过简单地附加 /uploads?alt=rss 来检索 YouTube 用户的(公开访问的)视频供稿。例如http://gdata.youtube.com/feeds/base/users/NTVKenya 给了 http://gdata.youtube.com/feeds/base/users/NTVKenya/uploads?alt=rss。但是此服务不再可用。

我猜现在推荐的方法是使用 GData 库。但是,使用此服务给我 com.google.gdata.util.NoLongerAvailableException 异常:

        YouTubeService service = new YouTubeService("service"); 
        ArrayList<String> urls = new ArrayList<String>();
        VideoFeed videoFeed = service.getFeed(new URL('http://gdata.youtube.com/feeds/base/users/NTVKenya'), VideoFeed.class);
        for (VideoEntry videoEntry : videoFeed.getEntries() ) {
            urls.add( videoEntry.getHtmlLink().getHref() );
        }

这给出:

        com.google.gdata.util.NoLongerAvailableException: No longer available
        <errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>NoLongerAvailableException</code><internalReason>No longer available</internalReason></error></errors>

我哪里错了?

谢谢。

这比我预期的要难得多!

关键是您现在需要一个 YouTube 开发者 API 密钥。 您可以在以下位置获取密钥: https://console.developers.google.com

创建应用程序并获得密钥后,我对此处找到的新 V3 API 进行了修改: https://developers.google.com/youtube/v3/sample_requests

而且我能够构建一个似乎有效的 URL...您可能需要进一步研究和完善它。这是我尝试过的(用您的密钥替换 MYAPIKEYHERE): https://www.googleapis.com/youtube/v3/search?part=snippet&q=NTVKenya&order=viewCount&type=video&key=MYAPIKEYHERE

这是它返回的内容:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/8Pwx4tA-oE0lcjEgrRoqOeaeu4w\"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 484531,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/RzPtjac7Nh1ggOliIdOlMbB_qls\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "PywWIHqiwD0"
   },
   "snippet": {
    "publishedAt": "2011-11-18T15:57:15.000Z",
    "channelId": "UCekTpzKodObpOcmvVCFUvTw",
    "title": "Turkana woman breastfeeds orphaned goat",
    "description": "http://www.ntv.co.ke A woman in Turkana has been taking care of an orphaned she goat for five months in an unorthodox manner. The woman rescued the kid ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/PywWIHqiwD0/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/PywWIHqiwD0/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/PywWIHqiwD0/hqdefault.jpg"
     }
    },
    "channelTitle": "NTVKenya",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/boF8bbeOYRKjwV6Y_dmUEwIMD9Y\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "mmLD5ztBEp4"
   },
   "snippet": {
    "publishedAt": "2014-06-06T22:38:02.000Z",
    "channelId": "UCekTpzKodObpOcmvVCFUvTw",
    "title": "#theTrend: Socialite Vera Sidika's new look",
    "description": "Vera Sidika tells Larry Madowo about her skin lightening procedure, what she does for a living and her expensive lifestyle For more news visit ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/mmLD5ztBEp4/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/mmLD5ztBEp4/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/mmLD5ztBEp4/hqdefault.jpg"
     }
    },
    "channelTitle": "NTVKenya",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/Bt6PHnNvhHX1COI1T3SPm9DVwUE\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "fQOmP8bNjqw"
   },
   "snippet": {
    "publishedAt": "2013-04-27T19:23:09.000Z",
    "channelId": "UCekTpzKodObpOcmvVCFUvTw",
    "title": "Kenyan Spirit: Kenyan athlete gave up winning to help colleague",
    "description": "http://www.ntv.co.ke And now to a story about selflessness and sacrifice and its about a Kenyan athlete. A picture they say is worth a thousand words and when a ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/fQOmP8bNjqw/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/fQOmP8bNjqw/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/fQOmP8bNjqw/hqdefault.jpg"
     }
    },
    "channelTitle": "NTVKenya",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/ReuOIGBmLl_r53O88M9HMNlEwI4\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "LeyBaXQPe1E"
   },
   "snippet": {
    "publishedAt": "2013-11-03T20:39:58.000Z",
    "channelId": "UCekTpzKodObpOcmvVCFUvTw",
    "title": "NTV Investigates: Seeds of Sin",
    "description": "Religion has and will always be an emotive subject to many Kenyans. The constitution guarantees freedom of worship, but some are taking advantage of the ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/LeyBaXQPe1E/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/LeyBaXQPe1E/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/LeyBaXQPe1E/hqdefault.jpg"
     }
    },
    "channelTitle": "NTVKenya",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/E5tUCJn1PIsHvXyaUiRT9-ENiI8\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "zMtzSqLgkP8"
   },
   "snippet": {
    "publishedAt": "2012-04-23T19:15:19.000Z",
    "channelId": "UCekTpzKodObpOcmvVCFUvTw",
    "title": "Naked injustice:Ugandan women protest activist's arrest",
    "description": "http://www.ntv.co.ke Hundreds of women activists in Uganda stripped to protest the arrest of a fellow activist. The women accused the police of mishandling the ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/zMtzSqLgkP8/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/zMtzSqLgkP8/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/zMtzSqLgkP8/hqdefault.jpg"
     }
    },
    "channelTitle": "NTVKenya",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

从给定 YouTube 用户获取“上传”的另一种方法,您可以按照以下步骤操作:

  1. 转到您想要获取其“上传”供稿的 YouTube 频道。
  2. 获取它的 channel_id - 在这里查看更多信息。
  3. 将channel_id的第二个字符从“C”替换为“U[=33=” ]”。示例:channel_id:UCqBJ47FjJcl61fmSbcadAVg - 修改:UUqBJ47FjJcl61fmSbcadAVg.
  4. 将修改后的 channel_id 粘贴到 URL 中:https://www.youtube.com/feeds/videos.xml?playlist_id=<>

结果会是这样 URL:

https://www.youtube.com/feeds/videos.xml?playlist_id=UUqBJ47FjJcl61fmSbcadAVg

它带来了最新上传的15个视频。