Clarification of shortening and tweet truncation


I’ve inherited a Twitter app that was using Bitly for url shortening when composing the final tweet and have a question related to updating it to using the wrapper.

The existing app was imposing a 138 character limit on the total tweet length, under the assumption that the URL would already be shortened by Bitly when concatenated to the tweet text. Now that I want to remove Bitly, I understand that I can submit a tweet knowing that the URL portion will account for 23 characters when wrapped in by Twitter.
My question is this – suppose my tweet text + URL exceeds the 140 tweet limit, is the truncation only ever done on the text portion, leaving the URL fully intact? For example, if my tweet text is 150 characters, followed by a lengthy URL, can assume that 33 characters would be removed from the text portion, with the URL always treated as priority and never truncated?

If this is the case, then even if the wrapper were to increase to 25 characters, I would just lose 2 more characters from the text. Correct assumption?


Twitter itself / the API never truncates the text, it only wraps your URLs. So, you would need the text + short URL (currently 23 characters for the latter) to fit into the 140 character limit. You’ll have to truncate the text appropriately to accommodate the shortened URL inside the Tweet body.

There’s more on this in the Character Counting documentation (although the dynamic changes slightly in the future based on our recent announcement about upcoming changes to Tweets but ultimately the URL wrapping and text pieces are the same). You can use the twitter-text library to validate that your intended Tweet will fit inside the limit.


My understanding is that I cannot shorten my URLs to using the API. This is only something that happens once the tweet is posted to Twitter. So does this mean that:

  1. I should make sure the text portion does not exceed 117 characters when I have an additional URL
  2. That the URL length is otherwise irrelevant.
  3. If the total tweet length exceeds 140, text + shortened URL, the POST is rejected not truncated

Thanks for your assistance!


That’s exactly right!


Thanks, Andy.

Just out of curiosity – how often is that 23 character count for likely to change? The documentation suggests getting it once per day then caching the result.


The last time it changed was within the past 2 years (can’t remember the exact date, but i know I was here when it happened!) … it is not likely to change often, based on the namespace that the characters provide it will eventually have to tick up another unit I expect. The point here is that we declare the current config to you so you can adapt behaviour based on that - it’s up to you how often you check back for changes.


Thanks, again.

closed #8