如何获取Twitch视频缩略图URL?

时间:2017-10-13 04:18:09

标签: twitch twitch-api

Youtube等视频分享网站有一个视频缩略图终点 示例:http://img.youtube.com/vi/youtube_id/default.jpg
其中youtube_id =视频的ID

所以我可以做到 <img src="http://img.youtube.com/vi/youtube_id/default.jpg"> 没有问题

抽搐也有类似的东西吗?

1 个答案:

答案 0 :(得分:0)

更新2018年

Twitch要求您使用其API,以便可以访问视频缩略图。
显然是因为缩略图的网址可能会更改

这是有关访问抽搐视频缩略图的简单指南

  1. 您必须有权访问Twitch开发API-为此,您需要在https://glass.twitch.tv

  2. 注册一个帐户
  3. 注册帐户后,您必须从twitch开发人员仪表板中创建一个应用程序

  4. 创建应用程序后,将为您提供要用于该应用程序的客户端ID-请注意,该应用程序将是使用twitch API(例如您的网站)的应用程序

enter image description here

  1. 您现在可以将client_id作为查询字符串参数传递给https://api.twitch.tv/kraken/videos/106400740?client_id=xxxxxxx,其中106400740是视频ID(请注意,此处的“ kraken”是常量-不确定其名称后面的来源)-请注意,如果您不包含client_id
  2. ,请求将返回一个包含错误消息的JSON对象。

请求将返回一个类似于以下内容的JSON对象:

{
  "title": "Door 5 vs Tilted Gamers",
  "description": "COOL Games: Killing Spree first match @ Mineski. Grove, Los Ba\u00f1os",
  "description_html": "COOL Games: Killing Spree first match @ Mineski. Grove, Los Ba\u00f1os<br>",
  "broadcast_id": 1,
  "broadcast_type": "upload",
  "status": "recorded",
  "language": "en",
  "tag_list": "",
  "views": 4,
  "created_at": "2017-11-08T03:13:12Z",
  "published_at": "2017-11-08T04:33:37Z",
  "url": "https:\/\/www.twitch.tv\/videos\/188543310",
  "_id": "v188543310",
  "recorded_at": "2017-11-08T03:13:12Z",
  "game": "Dota 2",
  "length": 2436,
  "preview": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000000-320x240.jpg",
  "animated_preview_url": "https:\/\/vod-storyboards.twitch.tv\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/storyboards\/188543310-strip-0.jpg",
  "thumbnails": [
    {
      "type": "generated",
      "url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000000-320x240.jpg"
    },
    {
      "type": "generated",
      "url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000006-320x240.jpg"
    },
    {
      "type": "generated",
      "url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000012-320x240.jpg"
    },
    {
      "type": "generated",
      "url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000018-320x240.jpg"
    }
  ],
  "fps": {
    "144p30": 29.999544341896,
    "360p30": 29.999544341896,
    "480p30": 29.999544341896
  },
  "resolutions": {
    "144p30": "256x144",
    "360p30": "640x360",
    "480p30": "852x480"
  },
  "channel": {
    "name": "esportsdotcool",
    "display_name": "esportsdotcool"
  },
  "_links": {
    "self": "https:\/\/api.twitch.tv\/kraken\/videos\/v188543310",
    "channel": "https:\/\/api.twitch.tv\/kraken\/channels\/esportsdotcool"
  }
}

在缩略图数组下,您可以找到视频的url

PS:如您所见,缩略图数组的长度为4-在这一点上,我认为这是因为视频作者可以放置的图像大小不同