Tens of millions of links are tweeted on Twitter each day. Wrapping these shared links helps Twitter protect users from malicious content while offering useful insights on engagement. All links submitted within tweets and direct messages, regardless of length, will eventually be wrapped with t.co.
Twitter uses twitter-text to parse status bodies and extract the entities, including URLs, that are returned with tweet responses.
At this time, the general rule of thumb as to which URLs will be wrapped in t.co:
We’re frequently making improvements to our parsing engine and because twitter-text is hosted on Github, you’re welcome to submit pull requests for bug fixes or parsing improvements.
We recommend the following when rendering links within Tweets:
Links will be wrapped when Twitter receives a tweet using POST statuses/update or a direct message using POST direct_messages/new. The wrapped link will be contained in the response to a successful request. You don’t need to make any extra API calls.
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_https to determine the current maximum length of wrapped URLs. We do not expect these values to change often.
It is important to note that you won’t necessarily know the length of a t.co URL before posting. Consider the
short_url_length field a maximum possible length for a t.co-wrapped link. When designing a tweet entry box, it’s best to consider all URLs as equalling the maximum possible
Counting characters in Tweets remains mostly the same.
help/configurationreports 20 characters as the maximum length, and a user posts a link that is 125 characters long, it should be considered as 20 characters long instead. If they post a link that is 18 characters long, it’s still only 18 characters long.
HTTPS-based URLs take an additional character for the additional “s” in the protocol aspect of the URL. You can better control the link tweeting experience by using the opt-in features offered today. Always use the values in GET help/configuration for best results.
URL shorteners will continue working with Twitter as they always have. While users won’t be able to opt-out of using t.co, developer use of Tweet Entities insures that users always see links with more meaningful semantics.
Use Tweet Entities, which are included by default on API responses, to detect the character position of URLs relative to tweet text, unwrapped URLs, and a suggested shortened display (like that used on Twitter.com). See this example from tmhOAuth for an example of consuming Tweet Entities in PHP.
No. If you have not implemented entities support, your users may see only t.co links instead of more descriptive indications. Taking advantage of the opt-in features today insures protection against future changes.
Not at this time. URLs are wrapped automatically at time of tweet or direct message submission. Resolved URLs are only available in the context of tweet or direct message content as part of the entities response accompanying the content.
At the time of writing, HTTP-based t.co links are 22 chars long. This will increase with time. Be sure to check the GET help/configuration endpoint to get the current max t.co link length.
Link wrapping provides an opportunity to learn how users engage with links contained in tweets. In the future, we may offer a set of APIs that developers can leverage to enrich their applications with gathered data.
When a HTTPS-based URL is passed while link wrapping is enabled using POST statuses/update or POST direct_messages/new, a HTTPS-based t.co link will be produced. HTTPS-based t.co links are one character longer than standard t.co links to account for the protocol change. GET help/configuration will indicate the current length of both HTTPS and non-HTTPS t.co URLs.
The lengths reported by GET help / configuration as maximums. It’s possible you can get a t.co link that is less characters long than the maximum.
Take a look on the Twitter text processing library we’re using for auto linking and extraction of usernames, lists & hashtags.