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:
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.