Verify tweet character count before tweet?

webintent

#1

I’m sharing my website content via tweet intent api like this: https://twitter.com/intent/tweet?url={my_url_to_share}&via={username}&text={tweet_text}&via={via} where the {my_url_to_share} contains meta tags with an image for the tweet or a video. The {tweet_text} is given by my website user and is dynamically applied before the tweet share button is created (so is not a fixed text) and this also happens with {via} parameter.

What i need is to get a way to know before the tweet share button is created if the tweet will have the properly character amount. Is there a way to make an api call to some url to verify that?


#2

The user will be able to edit the text in the web intent pop up, and that window should do character count checking itself, I believe - so I’m not completely sure why you’d want to do this yourself.

If you want to double-check character counts and URL tokenization, you could use the twitter-text library. Here’s an example I’ve used a couple of times.


#3

The thing is that an author (is a CMS) will be the creator of the share button that is different to the end user that will click the button to share the content so the validation that i want is for the author so the end user do not see that validation error in the tweet share window having to edit the tweet.

I’ll check that example, thank you!


#4

You use the “via” parameter twice in your example. The Tweet text template created with a via username component may add six characters in English or more in other languages – " via @{username}".

A provided URL, if published in the submitted Tweet, will be shortened to the length specified by the short_url_length_https property of the help/configuration API response.

Pre-selected text is straightforward character counting.


#5

Thank you for your response!
You are right about the double “via”, it was a typo in the post, the url used is https://twitter.com/intent/tweet?url={my_url_to_share}&via={username}&text={tweet_text} and my question now is how this calculation works if i don’t know how “via” will be (according to the language of the page)?
This question is after i start using the javascript provided by @andypiper on the previous answer.

Thanks again and regards.


#6

Depends on how many languages you expect to target and how many characters will be left for extra padding.

You may view Tweet templates by language by adding a lang query parameter to a Twitter.com page.
Example: https://twitter.com/intent/tweet?via=twitterdev&lang=ja


#7

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.