如何使用youtube api获取频道徽标?

时间:2012-02-23 14:47:12

标签: java youtube-api

我在youtube api库中使用java进行编程。如标题所示,我想获得youtube频道徽标的源链接(频道名称旁边左上角的图像)。例如:http://www.youtube.com/user/NationalGeographic这是我的尝试:

YouTubeService service = new YouTubeService("NationalGeographic");
String feedUrl = http://gdata.youtube.com/feeds/api/users/NationalGeographic/uploads;   
VideoFeed videoFeed = service.getFeed(new URL(feedUrl), VideoFeed.class);
String title = videoFeed.getTitle().getPlainText();

所以我得到了频道名称,但我无法获得频道徽标。请任何帮助。

2 个答案:

答案 0 :(得分:0)

我认为你不能用v2 API获得它(虽然我希望你可以),但这些图像的链接结构有点类似:

http://i2.ytimg.com/i/UHW94eEFW7hkUMVaZz4eDg/1.jpg?v=d69778
http://i4.ytimg.com/i/7-BWdwziR8LozMCBD1Ei7w/1.jpg?v=d8170b

想知道那些ids来自哪里......

答案 1 :(得分:0)

使用新的v3 API,您可以通过列出频道来获取它:

https://developers.google.com/youtube/v3/docs/channels/list

他们检索大小不同的徽标

以下是 Joe Rogan Experience 的输出:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"Fznwjl6JEQdo1MGvHOGaz_YanRU/_RZUfBijoiFpUwyyBzSuSJbKOi8\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"Fznwjl6JEQdo1MGvHOGaz_YanRU/zhDVFVQYUTKigur2_WU6BMjm2Qo\"",
   "id": "UCzQUP1qoWDoEbmsQxvdjxgQ",
   "snippet": {
    "title": "PowerfulJRE",
    "description": "The Joe Rogan Experience podcast",
    "customUrl": "joerogan",
    "publishedAt": "2013-01-12T01:40:14.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/a/AGF-l78OfG5OxzCfyyoFqw-dKeiFNGzTIT4YgpMK4Q=s88-c-k-c0xffffffff-no-rj-mo",
      "width": 88,
      "height": 88
     },
     "medium": {
      "url": "https://yt3.ggpht.com/a/AGF-l78OfG5OxzCfyyoFqw-dKeiFNGzTIT4YgpMK4Q=s240-c-k-c0xffffffff-no-rj-mo",
      "width": 240,
      "height": 240
     },
     "high": {
      "url": "https://yt3.ggpht.com/a/AGF-l78OfG5OxzCfyyoFqw-dKeiFNGzTIT4YgpMK4Q=s800-c-k-c0xffffffff-no-rj-mo",
      "width": 800,
      "height": 800
     }
    },
    "localized": {
     "title": "PowerfulJRE",
     "description": "The Joe Rogan Experience podcast"
    }
   },
   "contentDetails": {
    "relatedPlaylists": {
     "uploads": "UUzQUP1qoWDoEbmsQxvdjxgQ",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   },
   "statistics": {
    "viewCount": "1783605586",
    "commentCount": "0",
    "subscriberCount": "7180000",
    "hiddenSubscriberCount": false,
    "videoCount": "2305"
   }
  }
 ]
}