Hi all!
I have 2 questions:
I’m trying to post tweets from my website. When I count message length with Javascript (length property of textarea) and with PHP (mb_strlen) I get 140. But when I post this message via Twitter API (codebird) I get an error code 186 - “Status is over 140 characters”. I tried to normalize message with php normalizer but this doesn’t help. So, how do I count message length so it would be definitely the same length as twitter sees it?
Also, there is another problem: If I post just message without media (picture) - I dont get any errors. But if I post the same message with a photo I get error code 186 again. So, the second question is: How does picture affects the resulting message length?
Thank you very much for any response!
When you post a tweet with a media id you have to shorten it by the length of characters_reserved_per_media from help/configuration
Is there a reliable way to count the number of characters so as it Twitter does? For example "" Javascript: “”.length is 11 Twitter: the length of “” is 7 Is there a library of javascript functions for developers that can be used on a web-page to coordinate such calculations? Another example is URL. What is in Twitter considered as an URL? I am interested not in pages of instructions and advices, but a specific algorithm the same as uses Twitter.
Check the twitter-text library.
The length of "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66" differs when you put in Twitter and when you send from https://twitter.com/intent/tweet?text=👨👩👦👦 Something wrong with the calculations.
Where is the “twitter-text library”? And where to find the right algorithm?
Here’s the twitter-text library: https://github.com/twitter/twitter-text
Thanks. Tweet length is txt.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/mg, ' ').length I have not been experimenting with API but I can say that length of the unicode-string from my example is different in Twitter.
txt.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/mg, ' ').length
There’s more on how Twitter counts characters in the developer docs here.
not enough
It seems necessary to report a bug
Feel free to raise an issue on the twitter-text GitHub project with specific details and code samples.