LoginSignup
4
4

More than 5 years have passed since last update.

Twitterの動画投稿機能(video.twimg.com)で投稿した動画のURLをJSONから取得できるようになりました

Posted at

1月にTwitterの公式アプリから動画(30秒まで)がアップロードできるようになりました。

スクリーンショット 2015-02-03 1.09.17.png
https://twitter.com/n428dev/status/561814427150741505

2月からTwitter公式で開発者向けにビデオのURLをツイートのJSONから取得できるようになるというアナウンスがありましたが、私が試したところ2月7日にはビデオ情報がツイートのJSONに格納され返却されるようになっていました。

これをTwitterクライアントで生のJSONで取得すると以下になります

video_tweet.json
{
  "contributors": null,
  "text": "ツイッター動画投稿テスト http://t.co/y9hjEfABw1",
  "geo": null,
  "retweeted": false,
  "in_reply_to_screen_name": null,
  "possibly_sensitive": false,
  "truncated": false,
  "lang": "ja",
  "entities": {
    "symbols": [],
    "urls": [],
    "hashtags": [],
    "media": [
      {
        "sizes": {
          "thumb": {
            "w": 150,
            "resize": "crop",
            "h": 150
          },
          "small": {
            "w": 340,
            "resize": "fit",
            "h": 340
          },
          "large": {
            "w": 720,
            "resize": "fit",
            "h": 720
          },
          "medium": {
            "w": 600,
            "resize": "fit",
            "h": 600
          }
        },
        "id": 561814337585569800,
        "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "expanded_url": "http://twitter.com/n428dev/status/561814427150741505/video/1",
        "indices": [
          13,
          35
        ],
        "id_str": "561814337585569793",
        "type": "photo",
        "display_url": "pic.twitter.com/y9hjEfABw1",
        "url": "http://t.co/y9hjEfABw1"
      }
    ],
    "user_mentions": []
  },
  "in_reply_to_status_id_str": null,
  "id": 561814427150741500,
  "extended_entities": {
    "media": [
      {
        "sizes": {
          "thumb": {
            "w": 150,
            "resize": "crop",
            "h": 150
          },
          "small": {
            "w": 340,
            "resize": "fit",
            "h": 340
          },
          "large": {
            "w": 720,
            "resize": "fit",
            "h": 720
          },
          "medium": {
            "w": 600,
            "resize": "fit",
            "h": 600
          }
        },
        "id": 561814337585569800,
        "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "video_info": {
          "duration_millis": 11965,
          "variants": [
            {
              "bitrate": 832000,
              "content_type": "video/webm",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/480x480/QKhWzHdEK0QDPtg8.webm"
            },
            {
              "bitrate": 1280000,
              "content_type": "video/mp4",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/720x720/IdBKWbELa8D8cqLD.mp4"
            },
            {
              "bitrate": 320000,
              "content_type": "video/mp4",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/240x240/7EK_gSEEPFBATzXI.mp4"
            },
            {
              "bitrate": 832000,
              "content_type": "video/mp4",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/480x480/QKhWzHdEK0QDPtg8.mp4"
            },
            {
              "content_type": "application/x-mpegURL",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/pl/6G6kgS5lRXAOiCcg.m3u8"
            }
          ],
          "aspect_ratio": [
            1,
            1
          ]
        },
        "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "expanded_url": "http://twitter.com/n428dev/status/561814427150741505/video/1",
        "indices": [
          13,
          35
        ],
        "id_str": "561814337585569793",
        "type": "video",
        "display_url": "pic.twitter.com/y9hjEfABw1",
        "url": "http://t.co/y9hjEfABw1"
      }
    ]
  },
  "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
  "in_reply_to_user_id_str": null,
  "favorited": false,
  "in_reply_to_status_id": null,
  "retweet_count": 0,
  "created_at": "Sun Feb 01 09:12:52 +0000 2015",
  "in_reply_to_user_id": null,
  "favorite_count": 0,
  "id_str": "561814427150741505",
  "place": null,
  "user": {
    "location": "",
    "default_profile": true,
    "profile_background_tile": false,
    "statuses_count": 66,
    "lang": "ja",
    "profile_link_color": "0084B4",
    "id": 826661216,
    "following": false,
    "protected": false,
    "profile_location": null,
    "favourites_count": 5,
    "profile_text_color": "333333",
    "description": "428で働くプログラマー",
    "verified": false,
    "contributors_enabled": false,
    "profile_sidebar_border_color": "C0DEED",
    "name": "AKB428",
    "profile_background_color": "C0DEED",
    "created_at": "Sun Sep 16 07:06:52 +0000 2012",
    "is_translation_enabled": false,
    "default_profile_image": false,
    "followers_count": 9,
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/507934202185011200/HcQGt2_r_normal.jpeg",
    "geo_enabled": false,
    "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
    "follow_request_sent": false,
    "entities": {
      "description": {
        "urls": []
      }
    },
    "url": null,
    "utc_offset": 32400,
    "time_zone": "Irkutsk",
    "notifications": false,
    "profile_use_background_image": true,
    "friends_count": 40,
    "profile_sidebar_fill_color": "DDEEF6",
    "screen_name": "n428dev",
    "id_str": "826661216",
    "profile_image_url": "http://pbs.twimg.com/profile_images/507934202185011200/HcQGt2_r_normal.jpeg",
    "listed_count": 0,
    "is_translator": false
  },
  "coordinates": null
}

JSONの階層的に extended_entities -> media -> video_info

に動画情報が格納されています。
Youtubeのように各種のビットレート、各種の動画フォーマットにエンコードされた動画ファイルのURLが用意されています・

各種言語のTwitterのクライアントライブラリが対応するまではこのJSONを元に自前でゴリゴリパーサーを書くか、各種言語のライブラリを書き換えちゃいましょう。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4