Intent not decoding characters


#1

Hi there,

I’m having a weird behaviour using intents with php, i need to post a simple tweet using intents, this is the built url I’m using:

https://www.twitter.com/intent/tweet?url=http://bit.ly/tdWP8B&text=" . urlencode("¡Buen día aquí y ahora!") . "&hashtags=hazlorealidad

resulting in this url in the browser url bar:

https://twitter.com/intent/tweet?url=http://bit.ly/tdWP8B&text=%C2%A1Buen+d%C3%ADa+aqu%C3%AD+y+ahora%21&hashtags=hazlorealidad&original_referer=http://worldvision.devlab/

the intent popup appears and the all the urlencoded chars except whitespaces appear as not decoded, I mean i get this text in the textarea:

%C2%A1Buen d%C3%ADa aqu%C3%AD y ahora%21 http://bit.ly/tdWP8B #hazlorealidad

the plus signs are decoded into whitespaces but the rest of the chars remain encoded.

I’m getting mad with this, I try all the php function combinations possible, but no success.

Any clue on this issue?

Thanks in advance.

Diego.


#2

You’re double encoding the text. The correct URL would be https://twitter.com/intent/tweet?url=http://bit.ly/tdWP8B&text=¡Buen+día+aquí+y+ahora!&hashtags=hazlorealidad&original_referer=http://worldvision.devlab/


#3

Okie, now trying with this built url, removing the call to the urlencode php function

https://www.twitter.com/intent/tweet?url=http://bit.ly/tdWP8B&text=¡Buen+día+aquí+y+ahora!&hashtags=hazlorealidad

if I cut and paste the above url in a browser url bar i get this new transformed url

https://twitter.com/intent/tweet?url=http://bit.ly/tdWP8B&text=%C2%A1Buen+d%C3%ADa+aqu%C3%AD+y+ahora!&hashtags=hazlorealidad

and the next text in the popup textarea:

%22%C2%A1Buen d%C3%ADa aqu%C3%AD y ahora! http://bit.ly/tdWP8B #hazlorealidad

you are right, there is a double encoding, but don’t know where is made, not in my code, now I’m not making even a single encode, I’m totally lost with this.

Thanks for the quick response.

Regards, Diego.


#4

Probably your templating engine. What happens if you use:

"https://www.twitter.com/intent/tweet?url=http://bit.ly/tdWP8B&text=¡Buen día aquí y ahora!&hashtags=hazlorealidad"

#5

I just encountered this problem while forming the URL in pure Javascript (ie, no templating or server side language involved). For me, the issue is the “www” in front of “twitter.com”. Try this in the browser:

www.twitter.com/share?text=hello%20world

versus:

twitter.com/share?text=hello%20world

The www.twitter.com redirect to twitter.com is what is causing the double encoding, so I would pin the blame on Twitter.


#6

The solution from @weschow works for me.

Thanks !


#7

For above encoding issue solution is as below:

<?php $string = "hello who's this"; urlencode(html_entity_decode($string, ENT_COMPAT, 'UTF-8')); ?>

Found this solution here:
http://stackoverflow.com/questions/10771728/encoding-get-the-title-for-twitter-share-url#=

Solved my problem.

Thanks


#8