为什么按频道搜索会在媒体$ thumbnail标签内返回no_videos_140.png?

时间:2013-02-18 11:34:55

标签: youtube-api

1 个答案:

答案 0 :(得分:1)

我建议使用YouTube Data API的v3。如果您对搜索资源进行以下调用,它将返回三个不同的缩略图供您选择。如果频道尚未上传缩略图,则它将与您引用的剪影图像相同,但具有该频道的唯一网址。使用此网址作为您的img源的优势在于,如果频道决定上传缩略图,则无需更改图片即可反映该更改。

https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=ghghghgh&type=channel&key={YOUR_API_KEY}

响应:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"O7gZuruiUnq-GRpzm3HckV3Vx7o/PaWiOpjYBhvp7UVKUk3QeiagLtw\"",
 "pageInfo": {
  "totalResults": 33,
  "resultsPerPage": 2
 },
 "nextPageToken": "CAIQAA",
 "items": [
  {
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCLm-kPkFGRaV0t55q7-VwgQ"
   },
   "kind": "youtube#searchResult",
   "etag": "\"O7gZuruiUnq-GRpzm3HckV3Vx7o/x_NADGr-4b04fqoDn_uRBGj99eQ\"",
   "snippet": {
    "publishedAt": "2006-03-13T04:10:45.000Z",
    "channelId": "UCLm-kPkFGRaV0t55q7-VwgQ",
    "title": "barrett90",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "http://i.ytimg.com/i/Lm-kPkFGRaV0t55q7-VwgQ/1.jpg"
     },
     "medium": {
      "url": "http://i.ytimg.com/i/Lm-kPkFGRaV0t55q7-VwgQ/mq1.jpg"
     },
     "high": {
      "url": "http://i.ytimg.com/i/Lm-kPkFGRaV0t55q7-VwgQ/hq1.jpg"
     }
    }
   }
  }

您可以在此处获取API密钥: https://code.google.com/apis/console