3

full explanation:

I'm working on a project to generate twitter links that post over to twitter. My problem is twitter doesn't shorten the text correctly, and asks the user to fix the text. So I'm going to have javascript shorten the text to the maximum allowed without the extra being cut off by the user or twitter.

Agile Noob
  • 2,305
  • 4
  • 24
  • 35

2 Answers2

6

That's an unknown number because bitly will add characters as the namespace runs out. So it might be 21 today but 22 in a year. You may need to create the bitly links yourself before posting to Twitter.

Talljoe
  • 14,593
  • 4
  • 43
  • 39
  • 1
    so if I could ball park it for the next four years that would be fine, like assume a max length of 30 – Agile Noob Apr 22 '11 at 17:34
  • I know this is an old one but... Why not get the length of the returned string and deduct that from the available character space you have to work with. which in twitters case I beleive is 140 characters. – David Lloyd Brookes Jan 15 '13 at 04:33
0

This page tells you how to retrieve the current maximum length of a t.co URL generated by Twitter in real time, as part of a JSON string returned via a RESTful HTTP interface:

Twitter RESTful API Description

The relevant values shown for the sample request (YMMV) are:

"short_url_length_https": 23
"short_url_length": 22

These values will change (increase) monotonically over time, as Twitter runs out of combinations to represent the number of URLs submitted (and shortened) thus far.

According to this FAQ from Twitter:

https://dev.twitter.com/docs/tco-link-wrapper/faq

"The maximum length of t.co URLs will change over time. Issue a request daily to GET help/configuration and examine the fields short_url_length and short_url_length_https to determine the current maximum length of wrapped URLs. We do not expect these values to change often."

If your users are providing their own large links, Twitter should now shorten these correctly. At the time of your post, there might possibly have been some problem with that, but at the present time I think that this is working correctly.

However, you might want to provide more meaningful-looking shortened URLs, and Twitter supports this with something called Tweet Entities. I have not used these myself, but here is a link describing them:

Tweet Entities

Carl
  • 15,445
  • 5
  • 55
  • 53