Unwanted shortening of already shortened URLs (via t.co)


I’ve been running a website that uses the Twitter API for just about all user interaction. Users log in through Twitter (saved me from having to create my own login system). The user can opt-in to have their activity automatically tweeted as well. Every morning the site pulls in some data from an external source, formats it, saves it to a database, then tweets about it. I’ve written a function that will take all of the elements of the data (a title, description, value, and link) and make sure that it is 140 characters or less (by shortening the description if necessary). The problem I’ve been experiencing lately is that some of my tweets don’t actually make it through, apparently they’re being rejected by Twitter because they’re too long. Today was an example where some of the tweets went through and one didn’t. The one that didn’t would have been too long and so was shortened to be exactly 140 characters. This is the tweet text:

Daily: “Linked Up with Bungie.net” Link your gamertag with Bungie.net and play a game in Halo: Reach Match… - 3,000cR http://hrci.me/ch111

It is exactly 140 characters long, but I believe that the link (at 20 characters long) is causing it to fail. The link is a redirect, shortened specifically for Twitter using my own link shortener. I’m not sure what’s happening, but when I try to use TweetDeck to post the tweet (copied and pasted exactly as above), it fails. When I try tweeting it directly from Twitter.com, the length reports as -20 and it won’t let me post it. When I start deleting characters from the end of the URL the length stays at -20 until I delete the "e"at the end of hrci.me, then it goes to -13. Now, I used PHP’s strlen() function, and I also manually counted the characters…there are 140 exactly, so I really don’t understand why it’s doing this, or what I can do to fix it. Even if Twitter was wrapping the URL in a t.co one, t.co URLs are 20 characters max, meaning that the tweet would still be the same length.

Is anyone able to shed any light on this subject for me? I keep fielding questions from my followers asking why not all the tweets posted in the morning.


On further investigation I believe I’ve figured out why this is happening. The tweet contains details about challenges for the game Halo: Reach. This particular challenge is called “Linked Up With Bungie.net”, and it also contains Bungie.net in the description. Bungie.net is being read by Twitter as a URL and Twitter is trying to shorten it with t.co, but since it’s only 10 characters long, it’s actually being lengthened, making my 140 character tweet 20 characters longer (+10 characters for each lengthened instance of Bungie.net).

Devs, is there anything I can do about this? Short of (no pun intended) running the text through twitter-text-php to detect “URLs” inside the title and description, is there any way I can get it to not try to wrap URLs that don’t have a protocol? I can’t think of any situation where automatically wrapping anything that even looks like a link would be useful. For example, my keyboard sometimes misses spaces when I type, so I might end a sentence.and start another. Twitter would see that “sentence.and” and think it was a URL without a protocol and attempt to wrap it. Personally, I would ask you to just ignore all non-protocol-accompanied URLs alone, and it would seem that a lot of other people are of the same opinion, from what I’ve read here.


This is correct, bungie.net is a valid domain, so it’s being shortened according to the rules described here: https://dev.twitter.com/blog/twitter-text-library-and-tco-links-wrapping-update

In your example, sentence.and would not be shortened because it does not end in a valid gTLD.


Is there anything I can do about it? Perhaps escaping the dot in bungie.net so that it would display as a dot, but not be detected as a url? I don’t want bungie.net to be linked in the tweet.


Aside from mangling bungie.net to not pass the url validation in twitter text, no. The purpose is to preemptively prevent clients from autolinking such text to untrusted URLs when rendering your tweets.

As a rule, you shouldn’t count on a string like bungie.net not to be a link in all circumstances- clients will probably do all sorts of unintended manipulation of URL-like strings. For example, GMail hyperlinked bungie.net in the email notification I got from your original post.


What if you want to display the name of the site you are linking to? Why can’t you have the option of showing users where they will be taken with the link in your tweet. They will trust it more than a beneric t.co link and we will also get a chance to spread brand awareness by using our domain.

I also noticed sometimes bit.ly links still work - how are people doing this?



The domain of the URL will be shown in tweets within apps that implement tweet entities correctly – right now there’s a service issue where these aren’t being “unrolled” correctly but that will be resolved soon.


I’m actually talking about just regular tweets - nothing to do with apps. I can’t get a tweet to display just a normal domain like http://example.com


All tweets are displayed by apps – even the website is really just an application that displays & offers interactions with tweets and other related data. The same bug that prevents apps from resolving the URL correctly in your tweet text prevents the website from the same.


n/t edit sorry


I don’t understand what you’re trying to get across. I have the same concern as @Elleiope
I would like to post a link to a website, without it changing to some gibberish. If they see DanielRechel.com they will know what website I’m posting. If they see gibberish, they will not know where I’m sending them.