2016/12時点、Twitterから一番長い情報を取得する方法

当然のように公式クライアントのキーを使います。

1つのツイートに含まれている一番長い情報を取得する時に考えないといけないのは、140文字以上のフォーマットと投票。取得する方法はREST APIとstreaming APIの二種類がある。

・テキストだけで140文字のツイートをREST/streamingで取得
・他人のツイートを引用RTしてテキスト140文字のツイートをREST/Streamingで取得
・写真が複数枚あって140文字のテキストがあるツイートをREST/streamingで取得
・動画が一つあって140文字のツイートをREST/streamingで取得
・gifが一つあって140文字のツイートをREST/streamingで取得
・投票があって140文字のツイートをREST/streamingで取得。が、投票はstreaming apiでは取れない。
11種類について検証。jsonから必要と思われる項目のみ抽出。他人のツイートを引用RTした場合のパターンには、引用したツイートに動画があった場合・写真があった場合・孫RTした場合等あるがそこは考えないとする。

REST Apiについては`["tweet_mode"=>"extended","include_cards"=>"true","cards_platform"=>"iPhone-13"]`のパラメーターを追加している。その時、戻り値にtextのキーが消えてfull_textになるので受信側のプログラムで注意が必要。full_textが増えるだけでなく、textが消える。

また、画像に「説明」のテキストを追加する事が出来る模様。
http://qiita.com/riocampos/items/1f92177d359192d22566

また、REST APIで投票付きのツイートをリツイートしたツイートを取得すると、親ツイートに投票があるように見えるので注意

# 各種ツイートの戻り値json

```:テキストだけ＋Streaming
{
 "created_at": "Wed Dec 14 16:24:38 +0000 2016",
 "entities": {
  "hashtags": [],
  "symbols": [],
  "urls": [],
  "user_mentions": []
 },
 "id": 809071610086891520,
 "id_str": "809071610086891520",
 "in_reply_to_screen_name": null,
 "in_reply_to_status_id": null,
 "in_reply_to_status_id_str": null,
 "in_reply_to_user_id": null,
 "in_reply_to_user_id_str": null,
 "is_quote_status": false,
 "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
 "text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140",
 "timestamp_ms": "1481732678325",
 "truncated": false,
 "user": { /*略*/ }
}
```

```:他人のツイートを引用RT＋Streaming
{
 "created_at": "Wed Dec 14 16:55:35 +0000 2016",
 "display_text_range":[ 0, 140],
 "entities": {
  "hashtags": [],
  "symbols": [],
  "urls": [{
   "display_url": "twitter.com/i/web/status/8\u2026",
   "expanded_url": "https://twitter.com/i/web/status/809079397864984577",
   "indices": [ 117, 140],
   "url": "https://t.co/qNwhONpfzx"
  }],
  "user_mentions": []
 },
 "extended_tweet": {
  "display_text_range":[ 0, 140],
  "entities": {
   "hashtags": [],
   "symbols": [],
   "urls": [{
    "display_url": "twitter.com/nhk_seikatsu/s\u2026",
    "expanded_url": "https://twitter.com/nhk_seikatsu/status/808993484757569536",
    "indices": [ 141, 164],
    "url": "https://t.co/qg0FpkXtly"
   }],
   "user_mentions": []
  },
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/qg0FpkXtly"
 },
 "id": 809079397864984577,
 "id_str": "809079397864984577",
 "in_reply_to_screen_name": null,
 "in_reply_to_status_id": null,
 "in_reply_to_status_id_str": null,
 "in_reply_to_user_id": null,
 "in_reply_to_user_id_str": null,
 "is_quote_status": true,
 "possibly_sensitive": false,
 "quoted_status": {
  "created_at": "Wed Dec 14 11:14:11 +0000 2016",
  "display_text_range": [ 0, 83],
  "entities": {
   "hashtags": [],
   "media": [{
    "display_url": "pic.twitter.com/x8Ez1P93Dj",
    "expanded_url": "https://twitter.com/nhk_seikatsu/status/808993484757569536/photo/1",
    "id": 808993364360052737,
    "id_str": "808993364360052737",
    "indices": [ 84, 107],
    "media_url": "http://pbs.twimg.com/media/CzofLbxUQAEWEig.jpg",
    "media_url_https": "https://pbs.twimg.com/media/CzofLbxUQAEWEig.jpg",
    "sizes": {
     "large": { "h": 490, "resize": "fit", "w": 867 },
     "medium": {"h": 490, "resize": "fit", "w": 867 },
     "small": { "h": 384, "resize": "fit", "w": 680 },
     "thumb": { "h": 150, "resize": "crop","w": 150 }
    },
    "type": "photo",
    "url": "https://t.co/x8Ez1P93Dj"
   }],
   "symbols": [],
   "urls": [],
   "user_mentions": []
  },
  "extended_entities": {"media": [{
   "display_url": "pic.twitter.com/x8Ez1P93Dj",
   "expanded_url": "https://twitter.com/nhk_seikatsu/status/808993484757569536/photo/1",
   "id": 808993364360052737,
   "id_str": "808993364360052737",
   "indices": [ 84, 107],
   "media_url": "http://pbs.twimg.com/media/CzofLbxUQAEWEig.jpg",
   "media_url_https": "https://pbs.twimg.com/media/CzofLbxUQAEWEig.jpg",
   "sizes": {
    "large": { "h": 490, "resize": "fit", "w": 867 },
    "medium": {"h": 490, "resize": "fit", "w": 867 },
    "small": { "h": 384, "resize": "fit", "w": 680 },
    "thumb": { "h": 150, "resize": "crop","w": 150 }
   },
   "type": "photo",
   "url": "https://t.co/x8Ez1P93Dj"
  }]},
  "id": 808993484757569536,
  "id_str": "808993484757569536",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": false,
  "possibly_sensitive": false,
  "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client<\/a>",
  "text": "【N7福岡良子のつぶやき】 きょうは鳥取・大山で雪が積もりましたが、このあとは九州など西日本の山沿いで雪が積もる所が。山陰～近畿では平地でも雪が積もるかもしれません。 https://t.co/x8Ez1P93Dj",
  "truncated": false,
  "user": {  /*略*/  }
 },
 "quoted_status_id": 808993484757569536,
 "quoted_status_id_str": "808993484757569536",
 "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
 "text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-----\u2026 https://t.co/qNwhONpfzx",
 "timestamp_ms": "1481734535076",
 "truncated": true,
 "user": {  /*略*/  }
}
```

```:写真が複数＋Streaming
{
 "created_at": "Wed Dec 14 16:27:52 +0000 2016",
 "display_text_range": [ 0, 140],
 "entities": {
  "hashtags": [],
  "symbols": [],
  "urls": [{
   "display_url": "twitter.com/i/web/status/8\u2026",
   "expanded_url": "https://twitter.com/i/web/status/809072425484709888",
   "indices": [ 117, 140],
   "url": "https://t.co/z7hdKdZ0w0"
  }],
  "user_mentions": []
 },
 "extended_tweet": {
  "display_text_range": [ 0, 140],
  "entities": {
   "hashtags": [],
   "media": [
    {
     "display_url": "pic.twitter.com/cHRosMlCC1",
     "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
     "id": 809072350364717057,
     "id_str": "809072350364717057",
     "indices": [ 141, 164],
     "media_url": "http://pbs.twimg.com/media/CzpnBBkUUAE8H63.jpg",
     "media_url_https": "https://pbs.twimg.com/media/CzpnBBkUUAE8H63.jpg",
     "sizes": {
      "large": { "h": 1152, "resize": "fit", "w": 2048 },
      "medium": {"h": 675,  "resize": "fit", "w": 1200 },
      "small": { "h": 383,  "resize": "fit", "w": 680  },
      "thumb": { "h": 150,  "resize": "crop","w": 150   }
     },
     "type": "photo",
     "url": "https://t.co/cHRosMlCC1"
    },
    {
     "display_url": "pic.twitter.com/cHRosMlCC1",
     "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
     "id": 809072372053479425,
     "id_str": "809072372053479425",
     "indices": [ 141,164],
     "media_url": "http://pbs.twimg.com/media/CzpnCSXUkAEZg6f.jpg",
     "media_url_https": "https://pbs.twimg.com/media/CzpnCSXUkAEZg6f.jpg",
     "sizes": {
      "large": { "h": 1152, "resize": "fit", "w": 2048 },
      "medium": {"h": 675,  "resize": "fit", "w": 1200 },
      "small": { "h": 383,  "resize": "fit", "w": 680  },
      "thumb": { "h": 150,  "resize": "crop","w": 150  }
     },
     "type": "photo",
     "url": "https://t.co/cHRosMlCC1"
    },
    {
     "display_url": "pic.twitter.com/cHRosMlCC1",
     "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
     "id": 809072393515741184,
     "id_str": "809072393515741184",
     "indices": [ 141, 164 ],
     "media_url": "http://pbs.twimg.com/media/CzpnDiUUsAAjR4M.jpg",
     "media_url_https": "https://pbs.twimg.com/media/CzpnDiUUsAAjR4M.jpg",
     "sizes": {
      "large": {  "h": 2048, "resize": "fit", "w": 1152 },
      "medium": { "h": 1200, "resize": "fit", "w": 675  },
      "small": {  "h": 680,  "resize": "fit", "w": 383  },
      "thumb": {  "h": 150,  "resize": "crop","w": 150  }
     },
     "type": "photo",
     "url": "https://t.co/cHRosMlCC1"
    },
    {
     "display_url": "pic.twitter.com/cHRosMlCC1",
     "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
     "id": 809072411005964289,
     "id_str": "809072411005964289",
     "indices": [ 141, 164],
     "media_url": "http://pbs.twimg.com/media/CzpnEjeUUAEhctz.jpg",
     "media_url_https": "https://pbs.twimg.com/media/CzpnEjeUUAEhctz.jpg",
     "sizes": {
      "large": { "h": 1920, "resize": "fit", "w": 1080 },
      "medium": {"h": 1200, "resize": "fit", "w": 675  },
      "small": { "h": 680,  "resize": "fit", "w": 383  },
      "thumb": { "h": 150,  "resize": "crop","w": 150  }
     },
     "type": "photo",
     "url": "https://t.co/cHRosMlCC1"
    }
   ],
   "symbols": [],
   "urls": [],
   "user_mentions": []
  },
  "extended_entities": {"media": [
   {
    "display_url": "pic.twitter.com/cHRosMlCC1",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
    "id": 809072350364717057,
    "id_str": "809072350364717057",
    "indices": [
     141,
     164
    ],
    "media_url": "http://pbs.twimg.com/media/CzpnBBkUUAE8H63.jpg",
    "media_url_https": "https://pbs.twimg.com/media/CzpnBBkUUAE8H63.jpg",
    "sizes": {
     "large": { "h": 1152, "resize": "fit", "w": 2048 },
     "medium": {"h": 675,  "resize": "fit", "w": 1200 },
     "small": { "h": 383,  "resize": "fit", "w": 680  },
     "thumb": { "h": 150,  "resize": "crop","w": 150  }
    },
    "type": "photo",
    "url": "https://t.co/cHRosMlCC1"
   },
   {
    "display_url": "pic.twitter.com/cHRosMlCC1",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
    "id": 809072372053479425,
    "id_str": "809072372053479425",
    "indices": [ 141, 164 ],
    "media_url": "http://pbs.twimg.com/media/CzpnCSXUkAEZg6f.jpg",
    "media_url_https": "https://pbs.twimg.com/media/CzpnCSXUkAEZg6f.jpg",
    "sizes": {
     "large": { "h": 1152,"resize": "fit", "w": 2048 },
     "medium": {"h": 675, "resize": "fit", "w": 1200 },
     "small": { "h": 383, "resize": "fit", "w": 680  },
     "thumb": { "h": 150, "resize": "crop","w": 150  }
    },
    "type": "photo",
    "url": "https://t.co/cHRosMlCC1"
   },
   {
    "display_url": "pic.twitter.com/cHRosMlCC1",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
    "id": 809072393515741184,
    "id_str": "809072393515741184",
    "indices": [ 141, 164],
    "media_url": "http://pbs.twimg.com/media/CzpnDiUUsAAjR4M.jpg",
    "media_url_https": "https://pbs.twimg.com/media/CzpnDiUUsAAjR4M.jpg",
    "sizes": {
     "large": {  "h": 2048, "resize": "fit", "w": 1152  },
     "medium": { "h": 1200, "resize": "fit", "w": 675   },
     "small": {  "h": 680,  "resize": "fit", "w": 383   },
     "thumb": {  "h": 150,  "resize": "crop","w": 150   }
    },
    "type": "photo",
    "url": "https://t.co/cHRosMlCC1"
   },
   {
    "display_url": "pic.twitter.com/cHRosMlCC1",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809072425484709888/photo/1",
    "id": 809072411005964289,
    "id_str": "809072411005964289",
    "indices": [
     141,
     164
    ],
    "media_url": "http://pbs.twimg.com/media/CzpnEjeUUAEhctz.jpg",
    "media_url_https": "https://pbs.twimg.com/media/CzpnEjeUUAEhctz.jpg",
    "sizes": {
     "large": { "h": 1920, "resize": "fit", "w": 1080 },
     "medium": {"h": 1200, "resize": "fit", "w": 675  },
     "small": { "h": 680,  "resize": "fit", "w": 383  },
     "thumb": { "h": 150,  "resize": "crop","w": 150  }
    },
    "type": "photo",
    "url": "https://t.co/cHRosMlCC1"
   }
  ]},
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/cHRosMlCC1"
 },
 "id": 809072425484709888,
 "id_str": "809072425484709888",
 "in_reply_to_screen_name": null,
 "in_reply_to_status_id": null,
 "in_reply_to_status_id_str": null,
 "in_reply_to_user_id": null,
 "in_reply_to_user_id_str": null,
 "is_quote_status": false,
 "possibly_sensitive": false,
 "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
 "text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-----\u2026 https://t.co/z7hdKdZ0w0",
 "timestamp_ms": "1481732872731",
 "truncated": true,
 "user": {  /*略*/  }
}

```

```:動画が一つ＋Streaming

{
 "created_at": "Wed Dec 14 16:29:55 +0000 2016",
 "display_text_range": [ 0, 140],
 "entities": {
  "hashtags": [],
  "symbols": [],
  "urls": [{
   "display_url": "twitter.com/i/web/status/8\u2026",
   "expanded_url": "https://twitter.com/i/web/status/809072938959794176",
   "indices": [ 117, 140],
   "url": "https://t.co/u1w8px19Tw"
  }],
  "user_mentions": []
 },
 "extended_tweet": {
  "display_text_range": [ 0, 140],
  "entities": {
   "hashtags": [],
   "media": [{
    "display_url": "pic.twitter.com/OL00BBQAxK",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809072938959794176/video/1",
    "id": 809072899134877697,
    "id_str": "809072899134877697",
    "indices": [ 141, 164 ],
    "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/809072899134877697/pr/img/hbOXeA8CxTMegjmi.jpg",
    "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/809072899134877697/pr/img/hbOXeA8CxTMegjmi.jpg",
    "sizes": {
     "large": { "h": 720, "resize": "fit", "w": 720 },
     "medium": {"h": 600, "resize": "fit", "w": 600 },
     "small": { "h": 340, "resize": "fit", "w": 340 },
     "thumb": { "h": 150, "resize": "crop","w": 150 }
    },
    "type": "video",
    "url": "https://t.co/OL00BBQAxK",
    "video_info": {
     "aspect_ratio": [ 1, 1],
     "duration_millis": 3174,
     "variants": [
      { "bitrate": 832000, "content_type": "video/mp4"             ,"url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/vid/480x480/fYLlV2KH52Wso8Dd.mp4" },
      {                    "content_type": "application/x-mpegURL", "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/pl/_VNarphgg5T_-huV.m3u8"         },
      { "bitrate": 1280000,"content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/vid/720x720/yfRhQYeu5BS8sJUA.mp4" },
      { "bitrate": 320000, "content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/vid/240x240/zpjHoSmClXSI3CMl.mp4" },
      {                    "content_type": "application/dash+xml",  "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/pl/_VNarphgg5T_-huV.mpd"          }
     ]
    }
   }],
   "symbols": [],
   "urls": [],
   "user_mentions": []
  },
  "extended_entities": {"media": [{
   "display_url": "pic.twitter.com/OL00BBQAxK",
   "expanded_url": "https://twitter.com/FushiharaCheck/status/809072938959794176/video/1",
   "id": 809072899134877697,
   "id_str": "809072899134877697",
   "indices": [ 141, 164 ],
   "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/809072899134877697/pr/img/hbOXeA8CxTMegjmi.jpg",
   "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/809072899134877697/pr/img/hbOXeA8CxTMegjmi.jpg",
   "sizes": {
    "large": { "h": 720, "resize": "fit", "w": 720 },
    "medium": {"h": 600, "resize": "fit", "w": 600 },
    "small": { "h": 340, "resize": "fit", "w": 340 },
    "thumb": { "h": 150, "resize": "crop","w": 150 }
   },
   "type": "video",
   "url": "https://t.co/OL00BBQAxK",
   "video_info": {
    "aspect_ratio": [ 1, 1 ],
    "duration_millis": 3174,
    "variants": [
     { "bitrate": 832000, "content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/vid/480x480/fYLlV2KH52Wso8Dd.mp4" },
     {                    "content_type": "application/x-mpegURL", "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/pl/_VNarphgg5T_-huV.m3u8"         },
     { "bitrate": 1280000,"content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/vid/720x720/yfRhQYeu5BS8sJUA.mp4" },
     { "bitrate": 320000, "content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/vid/240x240/zpjHoSmClXSI3CMl.mp4" },
     {                    "content_type": "application/dash+xml",  "url": "https://video.twimg.com/ext_tw_video/809072899134877697/pr/pl/_VNarphgg5T_-huV.mpd"          }
    ]
   }
  }]},
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/OL00BBQAxK"
 },
 "id": 809072938959794176,
 "id_str": "809072938959794176",
 "in_reply_to_screen_name": null,
 "in_reply_to_status_id": null,
 "in_reply_to_status_id_str": null,
 "in_reply_to_user_id": null,
 "in_reply_to_user_id_str": null,
 "is_quote_status": false,
 "possibly_sensitive": false,
 "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
 "text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-----\u2026 https://t.co/u1w8px19Tw",
 "timestamp_ms": "1481732995153",
 "truncated": true,
 "user": {  /*略*/  }
}
```

```:gif+Streaming
{"delete": {
 "status": {
  "id": 809072938959794176,
  "id_str": "809072938959794176",
  "user_id": 212836820,
  "user_id_str": "212836820"
 },
 "timestamp_ms": "1481733061516"
}}
{
 "created_at": "Wed Dec 14 16:31:18 +0000 2016",
 "display_text_range": [ 0, 140],
 "entities": {
  "hashtags": [],
  "symbols": [],
  "urls": [{
   "display_url": "twitter.com/i/web/status/8\u2026",
   "expanded_url": "https://twitter.com/i/web/status/809073288987033601",
   "indices": [ 117, 140 ],
   "url": "https://t.co/esRM3ZatZn"
  }],
  "user_mentions": []
 },
 "extended_tweet": {
  "display_text_range": [ 0, 140],
  "entities": {
   "hashtags": [],
   "media": [{
    "display_url": "pic.twitter.com/69vpnJi0Tg",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809073288987033601/photo/1",
    "id": 809073269244448770,
    "id_str": "809073269244448770",
    "indices": [ 141, 164 ],
    "media_url": "http://pbs.twimg.com/tweet_video_thumb/Czpn2gqUUAIkqSP.jpg",
    "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/Czpn2gqUUAIkqSP.jpg",
    "sizes": {
     "large": {  "h": 348, "resize": "fit", "w": 498 },
     "medium": { "h": 348, "resize": "fit", "w": 498 },
     "small": {  "h": 238, "resize": "fit", "w": 340 },
     "thumb": {  "h": 150, "resize": "crop","w": 150 }
    },
    "type": "animated_gif",
    "url": "https://t.co/69vpnJi0Tg",
    "video_info": {
     "aspect_ratio": [ 83, 58 ],
     "variants": [{ "bitrate": 0, "content_type": "video/mp4", "url": "https://video.twimg.com/tweet_video/Czpn2gqUUAIkqSP.mp4" }]
    }
   }],
   "symbols": [],
   "urls": [],
   "user_mentions": []
  },
  "extended_entities": {"media": [{
   "display_url": "pic.twitter.com/69vpnJi0Tg",
   "expanded_url": "https://twitter.com/FushiharaCheck/status/809073288987033601/photo/1",
   "id": 809073269244448770,
   "id_str": "809073269244448770",
   "indices": [ 141, 164 ],
   "media_url": "http://pbs.twimg.com/tweet_video_thumb/Czpn2gqUUAIkqSP.jpg",
   "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/Czpn2gqUUAIkqSP.jpg",
   "sizes": {
    "large": { "h": 348,"resize": "fit", "w": 498 },
    "medium": {"h": 348,"resize": "fit", "w": 498 },
    "small": { "h": 238,"resize": "fit", "w": 340 },
    "thumb": { "h": 150,"resize": "crop","w": 150 }
   },
   "type": "animated_gif",
   "url": "https://t.co/69vpnJi0Tg",
   "video_info": {
    "aspect_ratio": [ 83, 58],
    "variants": [{ "bitrate": 0,"content_type": "video/mp4","url": "https://video.twimg.com/tweet_video/Czpn2gqUUAIkqSP.mp4"}]
   }
  }]},
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/69vpnJi0Tg"
 },
 "id": 809073288987033601,
 "id_str": "809073288987033601",
 "in_reply_to_screen_name": null,
 "in_reply_to_status_id": null,
 "in_reply_to_status_id_str": null,
 "in_reply_to_user_id": null,
 "in_reply_to_user_id_str": null,
 "is_quote_status": false,
 "possibly_sensitive": false,
 "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
 "text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-----\u2026 https://t.co/esRM3ZatZn",
 "timestamp_ms": "1481733078606",
 "truncated": true,
 "user": {  /*略*/  }
}
```


```:テキストだけ＋REST
{
  "conversation_id": 809093023757783040,
  "created_at": "Wed Dec 14 17:49:43 +0000 2016",
  "display_text_range": [ 0, 140],
  "entities": {
    "hashtags": [],
    "symbols": [],
    "urls": [],
    "user_mentions": []
  },
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140",
  "id": 809093023757783040,
  "id_str": "809093023757783040",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": false,
  "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
  "supplemental_language": null,
  "truncated": false,
  "user": {  /*略*/  }
}
```

```:他人のツイートを引用RT＋REST
{
  "conversation_id": 809093896495955968,
  "created_at": "Wed Dec 14 17:53:11 +0000 2016",
  "display_text_range": [ 0, 140],
  "entities": {
    "hashtags": [],
    "symbols": [],
    "urls": [{
      "display_url": "twitter.com/nhk_news/statu\u2026",
      "expanded_url": "https://twitter.com/nhk_news/status/809012067206213632",
      "indices": [ 141, 164 ],
      "url": "https://t.co/DAyvRZ62hq"
    }],
    "user_mentions": []
  },
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/DAyvRZ62hq",
  "id": 809093896495955968,
  "id_str": "809093896495955968",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": true,
  "possibly_sensitive": false,
  "possibly_sensitive_appealable": false,
  "quoted_status": {
    "conversation_id": 809012067206213632,
    "created_at": "Wed Dec 14 12:28:02 +0000 2016",
    "display_text_range": [ 0, 70],
    "entities": {
      "hashtags": [{
        "indices": [ 37, 46 ],
        "text": "nhk_news"
      }],
      "symbols": [],
      "urls": [{
        "display_url": "www3.nhk.or.jp/news/html/2016\u2026",
        "expanded_url": "http://www3.nhk.or.jp/news/html/20161214/k10010807111000.html",
        "indices": [ 47, 70 ],
        "url": "https://t.co/Qh2cL8CRIp"
      }],
      "user_mentions": []
    },
    "full_text": "【速報 JUST IN 】サッカークラブＷ杯 鹿島がアジア勢初の決勝進出 #nhk_news https://t.co/Qh2cL8CRIp",
    "id": 809012067206213632,
    "id_str": "809012067206213632",
    "in_reply_to_screen_name": null,
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "is_quote_status": false,
    "possibly_sensitive": false,
    "possibly_sensitive_appealable": false,
    "source": "<a href=\"http://www.nhk.or.jp/\" rel=\"nofollow\">NHK<\/a>",
    "supplemental_language": null,
    "truncated": false,
    "user": {  /*略*/  }
  },
  "quoted_status_id": 809012067206213632,
  "quoted_status_id_str": "809012067206213632",
  "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
  "supplemental_language": null,
  "truncated": false,
  "user": { /*略*/ }
}
```

```:写真が複数＋REST
{
  "conversation_id": 809094174695788544,
  "created_at": "Wed Dec 14 17:54:18 +0000 2016",
  "display_text_range": [ 0, 140],
  "entities": {
    "hashtags": [],
    "media": [{
      "display_url": "pic.twitter.com/tGEKIb7ii8",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094174695788544/photo/1",
      "features": {
        "large": {"faces": []},
        "medium": {"faces": []},
        "orig": {"faces": []},
        "small": {"faces": []}
      },
      "id": 809094094773309440,
      "id_str": "809094094773309440",
      "indices": [ 141, 164 ],
      "media_url": "http://pbs.twimg.com/media/Czp6ytzUUAAj4w6.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Czp6ytzUUAAj4w6.jpg",
      "sizes": {
        "large": { "h": 1920, "resize": "fit", "w": 1080 },
        "medium": {"h": 1200, "resize": "fit", "w": 675  },
        "small": { "h": 680,  "resize": "fit", "w": 383  },
        "thumb": { "h": 150,  "resize": "crop","w": 150  }
      },
      "type": "photo",
      "url": "https://t.co/tGEKIb7ii8"
    }],
    "symbols": [],
    "urls": [],
    "user_mentions": []
  },
  "extended_entities": {"media": [
    {
      "display_url": "pic.twitter.com/tGEKIb7ii8",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094174695788544/photo/1",
      "ext_alt_text": null,
      "features": {
        "large": {"faces": []},
        "medium": {"faces": []},
        "orig": {"faces": []},
        "small": {"faces": []}
      },
      "id": 809094094773309440,
      "id_str": "809094094773309440",
      "indices": [ 141,164],
      "media_url": "http://pbs.twimg.com/media/Czp6ytzUUAAj4w6.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Czp6ytzUUAAj4w6.jpg",
      "sizes": {
        "large": { "h": 1920, "resize": "fit", "w": 1080 },
        "medium": {"h": 1200, "resize": "fit", "w": 675  },
        "small": { "h": 680,  "resize": "fit", "w": 383  },
        "thumb": { "h": 150,  "resize": "crop","w": 150   }
      },
      "type": "photo",
      "url": "https://t.co/tGEKIb7ii8"
    },
    {
      "display_url": "pic.twitter.com/tGEKIb7ii8",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094174695788544/photo/1",
      "ext_alt_text": null,
      "features": {
        "large": {"faces": [{ "h": 272, "w": 272, "x": 126, "y": 236 }]},
        "medium": {"faces": [{"h": 159, "w": 159, "x": 73,  "y": 138 }]},
        "orig": {"faces": [{  "h": 272, "w": 272, "x": 126, "y": 236 }]},
        "small": {"faces": [{ "h": 90,  "w": 90,  "x": 41,  "y": 78  }]}
      },
      "id": 809094112401969152,
      "id_str": "809094112401969152",
      "indices": [ 141, 164 ],
      "media_url": "http://pbs.twimg.com/media/Czp6zveUUAAYi3W.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Czp6zveUUAAYi3W.jpg",
      "sizes": {
        "large": { "h": 1152, "resize": "fit", "w": 2048  },
        "medium": {"h": 675,  "resize": "fit", "w": 1200  },
        "small": { "h": 383,  "resize": "fit", "w": 680   },
        "thumb": { "h": 150,  "resize": "crop","w": 150   }
      },
      "type": "photo",
      "url": "https://t.co/tGEKIb7ii8"
    },
    {
      "display_url": "pic.twitter.com/tGEKIb7ii8",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094174695788544/photo/1",
      "ext_alt_text": null,
      "features": {
        "large": {"faces": []},
        "medium": {"faces": []},
        "orig": {"faces": []},
        "small": {"faces": []}
      },
      "id": 809094133721632768,
      "id_str": "809094133721632768",
      "indices": [ 141, 164],
      "media_url": "http://pbs.twimg.com/media/Czp60-5UkAAcg3A.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Czp60-5UkAAcg3A.jpg",
      "sizes": {
        "large": {  "h": 1152, "resize": "fit", "w": 2048 },
        "medium": { "h": 675,  "resize": "fit", "w": 1200 },
        "small": {  "h": 383,  "resize": "fit", "w": 680  },
        "thumb": {  "h": 150,  "resize": "crop","w": 150  }
      },
      "type": "photo",
      "url": "https://t.co/tGEKIb7ii8"
    },
    {
      "display_url": "pic.twitter.com/tGEKIb7ii8",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094174695788544/photo/1",
      "ext_alt_text": null,
      "features": {
        "large": {"faces": []},
        "medium": {"faces": []},
        "orig": {"faces": []},
        "small": {"faces": []}
      },
      "id": 809094156005953536,
      "id_str": "809094156005953536",
      "indices": [ 141, 164],
      "media_url": "http://pbs.twimg.com/media/Czp62R6UUAAMDCb.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Czp62R6UUAAMDCb.jpg",
      "sizes": {
        "large": {  "h": 2048, "resize": "fit",  "w": 1152 },
        "medium": { "h": 1200, "resize": "fit",  "w": 675  },
        "small": {  "h": 680,  "resize": "fit",  "w": 383  },
        "thumb": {  "h": 150,  "resize": "crop", "w": 150  }
      },
      "type": "photo",
      "url": "https://t.co/tGEKIb7ii8"
    }
  ]},
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/tGEKIb7ii8",
  "id": 809094174695788544,
  "id_str": "809094174695788544",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": false,
  "possibly_sensitive": false,
  "possibly_sensitive_appealable": false,
  "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
  "supplemental_language": null,
  "truncated": false,
  "user": {  /*略*/ }
}
```

```:動画が一つ＋REST
{
  "conversation_id": 809094395622371328,
  "created_at": "Wed Dec 14 17:55:10 +0000 2016",
  "display_text_range": [ 0, 140],
  "entities": {
    "hashtags": [],
    "media": [{
      "display_url": "pic.twitter.com/TdiqeB4hJN",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094395622371328/video/1",
      "features": {},
      "id": 809094362193797121,
      "id_str": "809094362193797121",
      "indices": [ 141, 164 ],
      "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/809094362193797121/pr/img/RE4jeOMrvF9tfivG.jpg",
      "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/809094362193797121/pr/img/RE4jeOMrvF9tfivG.jpg",
      "sizes": {
        "large": {  "h": 720, "resize": "fit",  "w": 720 },
        "medium": { "h": 600, "resize": "fit",  "w": 600 },
        "small": {  "h": 340, "resize": "fit",  "w": 340 },
        "thumb": {  "h": 150, "resize": "crop", "w": 150 }
      },
      "type": "photo",
      "url": "https://t.co/TdiqeB4hJN"
    }],
    "symbols": [],
    "urls": [],
    "user_mentions": []
  },
  "extended_entities": {"media": [{
    "additional_media_info": {"monetizable": false},
    "display_url": "pic.twitter.com/TdiqeB4hJN",
    "expanded_url": "https://twitter.com/FushiharaCheck/status/809094395622371328/video/1",
    "ext_alt_text": null,
    "features": {},
    "id": 809094362193797121,
    "id_str": "809094362193797121",
    "indices": [ 141, 164],
    "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/809094362193797121/pr/img/RE4jeOMrvF9tfivG.jpg",
    "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/809094362193797121/pr/img/RE4jeOMrvF9tfivG.jpg",
    "sizes": {
      "large": {  "h": 720, "resize": "fit", "w": 720 },
      "medium": { "h": 600, "resize": "fit", "w": 600 },
      "small": {  "h": 340, "resize": "fit", "w": 340 },
      "thumb": {  "h": 150, "resize": "crop","w": 150 }
    },
    "type": "video",
    "url": "https://t.co/TdiqeB4hJN",
    "video_info": {
      "aspect_ratio": [ 1, 1 ],
      "duration_millis": 1637,
      "variants": [
        {                     "content_type": "application/dash+xml",  "url": "https://video.twimg.com/ext_tw_video/809094362193797121/pr/pl/bm1hLXjugyI-O3mZ.mpd"          },
        { "bitrate": 320000,  "content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809094362193797121/pr/vid/240x240/NEsdVjVOJvgaTrPv.mp4" },
        {                     "content_type": "application/x-mpegURL", "url": "https://video.twimg.com/ext_tw_video/809094362193797121/pr/pl/bm1hLXjugyI-O3mZ.m3u8"         },
        { "bitrate": 1280000, "content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809094362193797121/pr/vid/720x720/OCdBA2I6I2kJufXM.mp4" },
        { "bitrate": 832000,  "content_type": "video/mp4",             "url": "https://video.twimg.com/ext_tw_video/809094362193797121/pr/vid/480x480/aOHEF01xZorfioP_.mp4" }
      ]
    }
  }]},
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/TdiqeB4hJN",
  "id": 809094395622371328,
  "id_str": "809094395622371328",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": false,
  "possibly_sensitive": false,
  "possibly_sensitive_appealable": false,
  "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
  "supplemental_language": null,
  "truncated": false,
  "user": {  /*略*/ }
}

```

```:gif+REST
{
  "card": {
    "binding_values": {
      "card_url": {
        "scribe_key": "card_url",
        "string_value": "https://t.co/Ih01hHncQs",
        "type": "STRING"
      },
      "player_height": {
        "string_value": "200",
        "type": "STRING"
      },
      "player_image": {
        "image_value": {
          "alt": null,
          "height": 200,
          "url": "https://pbs.twimg.com/tweet_video_thumb/Czp7K5YVIAAgGs7.jpg",
          "width": 272
        },
        "type": "IMAGE"
      },
      "player_image_large": {
        "image_value": {
          "alt": null,
          "height": 200,
          "url": "https://pbs.twimg.com/tweet_video_thumb/Czp7K5YVIAAgGs7.jpg",
          "width": 272
        },
        "type": "IMAGE"
      },
      "player_stream_content_type": {
        "string_value": "video/mp4 codecs=avc1.42E0",
        "type": "STRING"
      },
      "player_stream_url": {
        "string_value": "https://video.twimg.com/tweet_video/Czp7K5YVIAAgGs7.mp4",
        "type": "STRING"
      },
      "player_url": {
        "string_value": "https://video.twimg.com/tweet_video/Czp7K5YVIAAgGs7.mp4",
        "type": "STRING"
      },
      "player_width": {
        "string_value": "272",
        "type": "STRING"
      }
    },
    "card_platform": {"platform": {
      "audience": {
        "bucket": null,
        "name": "production"
      },
      "device": {
        "name": "iPhone",
        "version": "13"
      }
    }},
    "card_type_url": "http://card-type-url-is-deprecated.invalid",
    "name": "animated_gif",
    "url": "https://t.co/Ih01hHncQs"
  },
  "conversation_id": 809094519673090048,
  "created_at": "Wed Dec 14 17:55:40 +0000 2016",
  "display_text_range": [ 0, 140],
  "entities": {
    "hashtags": [],
    "symbols": [],
    "urls": [{
      "display_url": "pic.twitter.com/Ih01hHncQs",
      "expanded_url": "https://twitter.com/FushiharaCheck/status/809094519673090048/photo/1",
      "indices": [ 141, 164 ],
      "url": "https://t.co/Ih01hHncQs"
    }],
    "user_mentions": []
  },
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140 https://t.co/Ih01hHncQs",
  "id": 809094519673090048,
  "id_str": "809094519673090048",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": false,
  "possibly_sensitive": false,
  "possibly_sensitive_appealable": false,
  "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
  "supplemental_language": null,
  "truncated": false,
  "user": { /*略*/ }
}

```

```:投票+REST
{
  "card": {
    "binding_values": {
      "api": {
        "string_value": "capi://passthrough/1",
        "type": "STRING"
      },
      "card_url": {
        "scribe_key": "card_url",
        "string_value": "https://twitter.com",
        "type": "STRING"
      },
      "choice1_label": {
        "string_value": "1111",
        "type": "STRING"
      },
      "choice2_label": {
        "string_value": "22",
        "type": "STRING"
      },
      "choice3_label": {
        "string_value": "33",
        "type": "STRING"
      },
      "choice4_label": {
        "string_value": "4444",
        "type": "STRING"
      },
      "counts_are_final": {
        "boolean_value": false,
        "type": "BOOLEAN"
      },
      "duration_minutes": {
        "string_value": "10080",
        "type": "STRING"
      },
      "end_datetime_utc": {
        "string_value": "2016-12-21T17:56:23Z",
        "type": "STRING"
      }
    },
    "card_platform": {"platform": {
      "audience": {
        "bucket": null,
        "name": "production"
      },
      "device": {
        "name": "iPhone",
        "version": "13"
      }
    }},
    "card_type_url": "http://card-type-url-is-deprecated.invalid",
    "name": "poll4choice_text_only",
    "url": "card://809094699923292160"
  },
  "conversation_id": 809094701185781760,
  "created_at": "Wed Dec 14 17:56:23 +0000 2016",
  "display_text_range": [ 0, 140],
  "entities": {
    "hashtags": [],
    "symbols": [],
    "urls": [],
    "user_mentions": []
  },
  "full_text": "--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100-------110-------120-------130-------140",
  "id": 809094701185781760,
  "id_str": "809094701185781760",
  "in_reply_to_screen_name": null,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "is_quote_status": false,
  "possibly_sensitive": false,
  "possibly_sensitive_appealable": false,
  "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
  "supplemental_language": null,
  "truncated": false,
  "user": { /*略*/ }
}

```

# 全てのデータを取得するには

StreamingApiの時はこうなる

```
if(extended_tweetがある){
	text = extended_tweet.full_text
	videoOrPhoto = extended_tweet.extended_entities.media
}else{
	text = text
}
```

REST Apiの時はこうなる

```
if(extended_entitiesがある){
	text = extended_entities.full_text;
	videoOrPhoto = extended_entities.entities.media
}else{
	text = full_text
}
```

という感じかな。

# 140文字緩和後のツイート

REST APIにおいては`tweet_mode=extended`を指定する。streaming apiではキー名が増えるのでリクエストに変更は不要。

# 投票付きツイートの取得について

[Twitterのアンケート関連のAPIのサンプル](https://gist.github.com/mpyw/fe6741f1348ff63b255d8a6c8d99b405) がとても参考になった。
公式クライアントのキーで、`"include_cards" => true, "cards_platform" => "iPhone-13"`のパラメーターが付いていて、REST APIである。全ての条件がandで通ったらツイート情報が取得出来る。
つまり、ストリーミングapiでは取れない。確認した。

# 参考URL

* [Twitter4Jの140文字制限拡張対応について \- Qiita](http://qiita.com/takke/items/559b99152eb90a897a65)
* [Twitterの字数カウント変更で公式以外はツイートの尻尾が切れる\!? \- Togetterまとめ](http://togetter.com/li/1027065)
* [Twitter4JのExtendedMediaEntity廃止について \- Qiita](http://qiita.com/takke/items/0bd8be655bc95ab78185)
* [Twitterのアンケート関連のAPIを解析したお話 \- Hiroto's diary](http://hiroto-k.hatenablog.com/entry/2016/02/20/191159) ←実際に取得する方法は全部ここに書いてある
* [Twitterのアンケート関連のAPIのサンプル](https://gist.github.com/mpyw/fe6741f1348ff63b255d8a6c8d99b405) ←実際に取得する方法は全部ここに書いてある
* [投票ツイート情報を取得するAPI](https://twpollapi.azyobuzi.net/)
*