How to get long tweets (>140 characters)

streaming
python
api
twython

#1

I’m using the Python package Twython to follow a couple of Twitter users with the streaming API. Basically, everything works just fine.

The only issue I’ve noticed is that tweet coming over the stream with more then 140 characters get shorted to “Something something… http://t.co/xyz” with the whole string less or equal than 140 characters. When I open the link in a browser, I can see the tweet it in it’s fill length (and without the URL).

Does this work as intended? I would like to get the full-length in my streaming results? While I couldn’t see why, could this be a problem with Twython?


#2

You should find that the Tweet objects contain an additional extended_tweet object. Here’s an example. The top-level truncated field is set to true so there’s an extended_tweet object lower down, which contains a full_text field with the full value.

{
  "created_at": "Wed Nov 15 23:40:51 +0000 2017",
  "id": 930943709205749761,
  "id_str": "930943709205749761",
  "text": "@andypiper I was being chased by a giant dinosaur, but I think I've managed to give it the slip. Oh, you've got a d\u2026 https:\/\/t.co\/kCFrM13o4v",
  "display_text_range": [11, 140],
  "source": "\u003ca href=\"http:\/\/wibble.org\" rel=\"nofollow\"\u003esimpletester123\u003c\/a\u003e",
  "truncated": true,
  "in_reply_to_status_id": 720316051825762304,
  "in_reply_to_status_id_str": "720316051825762304",
  "in_reply_to_user_id": 786491,
  "in_reply_to_user_id_str": "786491",
  "in_reply_to_screen_name": "andypiper",
  "user": {
    "id": 54931584,
    "id_str": "54931584",
    "name": "Evil Piper",
    "screen_name": "evilpiper",
    "location": null,
    "url": null,
    "description": "mwah-ha-haaaaa (aka, squirrel!)",
    "translator_type": "none",
    "protected": false,
    "verified": false,
    "followers_count": 31,
    "friends_count": 22,
    "listed_count": 0,
    "favourites_count": 39,
    "statuses_count": 668,
    "created_at": "Wed Jul 08 15:40:42 +0000 2009",
    "utc_offset": 0,
    "time_zone": "London",
    "geo_enabled": true,
    "lang": "en",
    "contributors_enabled": false,
    "is_translator": false,
    "profile_background_color": "1A1B1F",
    "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",
    "profile_background_tile": false,
    "profile_link_color": "91061F",
    "profile_sidebar_border_color": "181A1E",
    "profile_sidebar_fill_color": "949399",
    "profile_text_color": "120312",
    "profile_use_background_image": false,
    "profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/860122276469116929\/k3npzTav_normal.jpg",
    "profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/860122276469116929\/k3npzTav_normal.jpg",
    "profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/54931584\/1400069736",
    "default_profile": false,
    "default_profile_image": false,
    "following": null,
    "follow_request_sent": null,
    "notifications": null
  },
  "geo": null,
  "coordinates": null,
  "place": null,
  "contributors": null,
  "is_quote_status": false,
  "extended_tweet": {
    "full_text": "@andypiper I was being chased by a giant dinosaur, but I think I've managed to give it the slip. Oh, you've got a dinosaur too! Come on, Team Not Dead. It\u2019s a bit more exciting when you go the other way...",
    "display_text_range": [11, 205],
    "entities": {
      "hashtags": [],
      "urls": [],
      "user_mentions": [{
        "screen_name": "andypiper",
        "name": "andy piper (pipes)",
        "id": 786491,
        "id_str": "786491",
        "indices": [0, 10]
      }],
      "symbols": []
    }
  },
  "quote_count": 0,
  "reply_count": 0,
  "retweet_count": 0,
  "favorite_count": 0,
  "entities": {
    "hashtags": [],
    "urls": [{
      "url": "https:\/\/t.co\/kCFrM13o4v",
      "expanded_url": "https:\/\/twitter.com\/i\/web\/status\/930943709205749761",
      "display_url": "twitter.com\/i\/web\/status\/9\u2026",
      "indices": [117, 140]
    }],
    "user_mentions": [{
      "screen_name": "andypiper",
      "name": "andy piper (pipes)",
      "id": 786491,
      "id_str": "786491",
      "indices": [0, 10]
    }],
    "symbols": []
  },
  "favorited": false,
  "retweeted": false,
  "filter_level": "low",
  "lang": "en",
  "timestamp_ms": "1510789251029"
}

#3

Perfect, thanks a lot!


#4