JTwitter is too strict on checking post length

22 views
Skip to first unread message

jjd

unread,
Oct 17, 2012, 2:15:16 PM10/17/12
to jt...@googlegroups.com
In Twitter.updateStatus2_vars there is a check that the status you are about to post is 140 characters or less.  If it isn't, a java.lang.IllegalArgumentException is thrown with a message saying as much.

Unfortunately, sometimes this restriction is too tight.  For example: Let's say I'm posting a status that is (say) 144 characters and it contains a URL.  if I try to post this, I get an error saying "Status text must be 140 characters or less".  If I truncate my status to 140 characters and retry, then the post is successful.  

However, (say) when twitter gets its hands on my status, it shortens the URL to a t.co URL and posts it such that now my status is actually only 136 characters and I'm wasting valuable characters.

What can be done to modify JTwitter to allow me to post a status that will end up being 140 characters?  In my case, I've actually used Twitter's text-js javascript library to ensure that it will fit before calling JTwitter.  I'd rather JTwitter allow me to send a status somewhat larger than 140 characters so that when URLs are modified and the length really is 140 characters, twitter will post all 140 characters.

How about an optional version of Twitter.updateStatus that doesnt' do this test and instead requires the caller to verify the validity of the tweet in advance?

--Jim--



Daniel Winterstein

unread,
Oct 17, 2012, 2:22:53 PM10/17/12
to jt...@googlegroups.com, group-...@soda.sh
Hi Jim,

Could you send me an example of a tweet that broke the length check?
JTwitter does correct for url length -- so this may be a case where my
url regex is too strict.

> How about an optional version of Twitter.updateStatus that doesnt' do this
> test and instead requires the caller to verify the validity of the tweet in
> advance?

Good idea.
I'll make it a flag that toggles length checking on/off.

Best regards,
- Daniel
--
--------------------------------------------------
Dr Daniel Winterstein
Edinburgh
http://winterwell.com http://soda.sh

jjd

unread,
Oct 17, 2012, 2:58:40 PM10/17/12
to jt...@googlegroups.com, group-...@soda.sh
It appears I may have misspoken.  The tweet I was dealing with was this 143 character tweet:

"When an insulting tweet was sent by @KitchenAidUSA, they had a big disaster to deal with http://on.mash.to/R3JOqY I think they managed it well!"

When I just tested this tweet with JTwitter, it allowed the tweet (as it should).

Here's some background to explain why I thought there was a problem:

A user of ours composed a longer tweet than this which was carefully crafted to truncate at 140 characters so that twitter would get the above tweet and other social networks would get a longer status.  My software truncated it at (literal) 140 characters  (which was wrong) causing a 136 character tweet to be posted by twitter.

I then changed my software to instead allow some "wiggle room" and truncate the twitter post to 160 characters, assuming that twitter itself would further truncate to the correct position. However, at this point, JTwitter wouldn't allow the post saying it was more than 140 characters.  I mistakenly assumed that JTwitter was checking the length of my input, not a massaged version of my input.

Apparently, I need to instead figure out exactly where twitter will truncate the post and truncate to that point.  I had been resisting this because I didn't want to write the function to emulate twitter's behavior to truncate at the precise point.  I would be happier to have the "non checking" version of updateStatus I mentioned above.

Let me now leave this topic and instead just rant about how idiotic Twitter's URL 'shortening' method is.  An example is that they will change a post written as "I love amazon.com!" to "I love http://t.co/LFqNfEK3!".  Of course, in their UI, they'll display this as "I love amazon.com!"  and expect every other client that reads their stream to use their API to convert their short link back to a domain name.  Very annoying.

Thanks,

--Jim--

jjd

unread,
Oct 17, 2012, 3:14:13 PM10/17/12
to jt...@googlegroups.com, group-...@soda.sh
I thought I had a good solution when I just looked at the JTwitter API and just said "Oh, I can use Twitter.splitMessage().get(0) to get the first portion of the message using Twitter's count, but it appears you didn't bother to implement their URL counting method either... :-)


Reply all
Reply to author
Forward
0 new messages