tags:

views:

807

answers:

4

Hi,

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.

A: 

You could try just posting right to Twitter:

<form action="http://www.twitter.com/home" method="GET">
    <textarea name="status">

...

Lucas Jones
Keep it simple, eh? Didn't think of that!However, I'd like to have more control over the structure of the tweet, without relying on JS too much.Thanks though, this may be the way!
Rich
I know what you mean... I personally wouldn't mind relying on JS (as long as it only works when JS is enabled, obviously), as http://twitter.com wants JS as well.
Lucas Jones
+2  A: 

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

FRotthowe
I also needed to take out the www then it worked a treat! Thanks!
Rich
Yeah, oddly taking out the www worked for me too.
evanmcd
+5  A: 

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.

Hejazi
Cheers for that :)I mentioned this in my chosen answer above too!
Rich
A: 

Hmm. At least when using the new Twitter layout ... this:

http://twitter.com/home?status=This+is+a+test+%26+So+is+this

... redirects to this (when logged in):

http://twitter.com/?status=This%20is%20a%20test%20&amp;%20So%20is%20this

(notice the unencoded &) ... and the tweet-in-waiting becomes:

This is a test

:(

Myriad adjustments and variations didn't help. (Sigh.)

Admittedly sketchy workaround: Change & (%26) to + (%2B). It may be advisable do this with plain text, before (re-)introducing entities into the equation (e.g., don't change %26 to %2B). Measure twice, cut once, as they say.

Joe D'Andrea