Tweet length ok in Twitter User Interface but too long through API


#1

Consider the following tweet :

#RobertHalf is looking for a 3+yrs ASP.NET Immediate Opening, apply now! (#Baltimore) #job http://workfor.us/roberthalftechnology/cp8n349

I can post it using Twitter User interface (@soffyjames) : post_id = 514123304341630977

But when I try to update my status using API, I get an error

ApiServerError: # API method: ‘update_with_media’
Code: 186
Raw error: u’[{“message”: “Status is over 140 characters.”, “code”: 186}]‘
API args: {‘status’: u’#RobertHalf is looking for a 3+yrs ASP.NET Immediate Opening, apply now! (#Baltimore) #job http://workfor.us/roberthalftechnology/cp8n349’, ‘headers’: {‘Content-Length’: ‘124302’, ‘Content-Type’: ‘multipart/form-data; boundary=WorK4Rock’, ‘Host’: ‘api.twitter.com’, ‘Authorization’: …}


#2

Your post using the Twitter UI is just text. Your API example shows that you’re using update_with_media, ie. trying to additionally attach an image. I expect that it’s the image which takes you past 140 characters; using statuses/update instead of statuses/update_with_media would likely work.


#3

Including an image with a Tweet generally reduces your character limit by 23. If you make a call to https://api.twitter.com/1.1/help/configuration.json, you’ll see the “characters_reserved_per_media” property in the response. This property name is misleading because it is not 23 characters per media, but rather 23 characters total for any number of media. Try it in the UI directly at twitter.com. You’ll see that if you type in 140 characters and then attach an image to the Tweet, you’re all of a sudden at -23 characters.

Hey Twitter, PLEASE update your documentation with respect to how images count toward your character limit. The only way I can prove this to other developers on my team is by writing integration tests, and by demonstrating how it works in the twitter.com UI. I have ZERO documentation to back up my claims. If any documentation exists, I cannot find it and would be happy for someone to point it out to me.

This article says that your length will updated when you attach an image, but it doesn’t explain anything and doesn’t pertain specifically to developers. -->https://support.twitter.com/articles/20156423-posting-photos-on-twitter


Update API counting msg length incorrectly
#4

using statuses/update instead of statuses/update_with_media would likely work.

/statuses/update with the media_ids parameter exhibits the same behavior. Essentially, images count as 23 characters (short_url_length of 22 plus a space character) total, regardless of the endpoint you use, and regardless of the number of images. The Tweet that @soffyjames posted above worked in the Twitter UI because he did not attach an image. It failed using the API because he attached an image.