LoginSignup
17
17

More than 5 years have passed since last update.

Twitterのビデオ投稿機能(video.twimg.com)で投稿した動画のURLをAPIで取得(できるのは2月以降らしい

Last updated at Posted at 2015-02-02

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

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

まずはiPhoneアプリからで順次対応していくようです。

ここでプログラムからTwitterのツイートから動画URLだけ抜き出して動画収集したいところですが公式にTwitterのAPI側で対応するのは2月初旬以降のようです。

Twitter開発フォーラム) https://twittercommunity.com/t/twitter-video-support-in-rest-and-streaming-api/31258

現在の動画URLの仕様ですが

上記の図のツイートのURLが
https://twitter.com/n428dev/status/561814427150741505

このツイートをJavaのTwitter4JでStatus.Textで取得すると
ツイッター動画投稿テスト http://t.co/y9hjEfABw1

となる。

はURL展開されると

に展開され、そのページのHTMLソースを見ると

に動画URLがおかれる。
動画は今回はWebMが使用されているようだ。
この動画URLをTwitterAPI経由で取得したいところだが現在は公式が改修が終わってないようでまだ取得できないらしい。

上記のTwitterのツイートの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": [],
    "user_mentions": []
  },
  "in_reply_to_status_id_str": null,
  "id": 561814427150741500,
  "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": 64,
    "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
}

動画系の情報はいっさい入っていないためTwitter4JのStatus.getExtendedMediaEntities()をつかっても動画のURLは返ってこないが、2月以降Twitterから以下のようなJSONが付随してかえってくるようになるらしいので、現状のTwitterライブラリのままで動画URLの取得はできるようである。

"extended_entities":{
  "media": [
    {
      "display_url": "pic.twitter.com\/31JoMS50ha",
      "expanded_url": "http:\/\/twitter.com\/twitter\/status\/560070183650213889\/video\/1",
      "features": {

      },
      "id": 5.6007013197639e+17,
      "id_str": "560070131976392705",
      "indices": [
        110,
        132
      ],
      "media_url": "http:\/\/pbs.twimg.com\/ext_tw_video_thumb\/560070131976392705\/pu\/img\/TcG_ep5t-iqdLV5R.jpg",
      "media_url_https": "https:\/\/pbs.twimg.com\/ext_tw_video_thumb\/560070131976392705\/pu\/img\/TcG_ep5t-iqdLV5R.jpg",
      "sizes": {
        "large": {
          "h": 576,
          "resize": "fit",
          "w": 1024
        },
        "medium": {
          "h": 337,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 191,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "video",
      "url": "http:\/\/t.co\/31JoMS50ha",
      "video_info": {
        "aspect_ratio": [
          16,
          9
        ],
        "duration_millis": 30033,
        "variants": [
          {
            "bitrate": 2176000,
            "content_type": "video\/mp4",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/1280x720\/c4E56sl91ZB7cpYi.mp4"
          },
          {
            "bitrate": 320000,
            "content_type": "video\/mp4",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/320x180\/nXXsvs7vOhcMivwl.mp4"
          },
          {
            "bitrate": 832000,
            "content_type": "video\/webm",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/640x360\/vmLr5JlVs2kBLrXS.webm"
          },
          {
            "bitrate": 832000,
            "content_type": "video\/mp4",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/640x360\/vmLr5JlVs2kBLrXS.mp4"
          },
          {
            "content_type": "application\/x-mpegURL",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/pl\/r1kgzh5PmLgium3-.m3u8"
          }
        ]
      }
    }
  ]
}
17
17
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
17
17