Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter URL encoding

Tags:

url

php

twitter

We're about to launch a little twitter Christmas competition, and I've run into a little snag.

To enter, people will need to post a tweet in the following format:

@user blah, blah, blah #hashtag

Currently, I have a form where they enter their answer (the blah, blah, blah) and a PHP script which encodes the entire statement and adds on the twitter url:

http://www.twitter.com/home?status=%40user%20blah%2Cblah%2Cblah%20%23hashtag

Then takes the user to twitter and puts the status in the update field.

However, whilst the spaces (%20) are decoded fine the @ and # characters remain as %40 & %23 respectively, even when the tweet is posted. I cannot put the actual characters in the url as twitter mistakes this for a search.

Is there any way to solve this? I'd like to do it without requiring username & password etc if possible.

Any help will be greatly appreciated.

like image 288
Rich Avatar asked Dec 08 '22 05:12

Rich


2 Answers

I've had the same problem, and the solution was very simple.

Just use
http://twitter.com/home?status=
instead of
http://www.twitter.com/home?status=
and it'll work as expected, even if the text isn't in ASCII.

If you want to know more details about this strange behavior see this blog post: http://www.kilometer0.com/blog/2010/01/21/twitter-status-urls-and-ampersands/

Hope this helps someone.

like image 111
Hejazi Avatar answered Dec 27 '22 23:12

Hejazi


Encode the spaces as + and it works: http://twitter.com/home?status=%40user+blah%2Cblah%2Cblah+%23hashtag

like image 22
FRotthowe Avatar answered Dec 27 '22 23:12

FRotthowe