Escaping plus signs and ampersands

2,583 views
Skip to first unread message

Harry

unread,
May 27, 2008, 8:52:33 PM5/27/08
to Twitter Development Talk
curl -u email:pass -d status="ampersand & and plus sign +"
http://twitter.com/statuses/update.xml
result --> "ampersand"
Where did the rest of the text go?

curl -u email:pass -d status="plus sign +" http://twitter.com/statuses/update.xml
result --> "plus sign"
Where did the plus sign go?

curl -u email:pass -d status="plus sign + and ampersand &"
http://twitter.com/statuses/update.xml
result --> "plus sign and ampersand"
Where did the plus sign and the ampersand go?

Other characters: status="@#$%^*()_-=[]{}\|;:'<>,./?"
result --> "@#$%^*()_-=[]{}\|;:'&amp;lt;&amp;gt;,./?"

Is there a way to escape the plus signs and ampersands?

Thanks,
Harry

e.p.c.

unread,
May 27, 2008, 8:56:38 PM5/27/08
to Twitter Development Talk
You have to URL encode any data POSTed via the API.
So & becomes %26, + becomes %2B.

Harry

unread,
May 27, 2008, 9:08:35 PM5/27/08
to Twitter Development Talk
On May 27, 6:56 pm, "e.p.c." <epcoste...@gmail.com> wrote:
> You have to URL encode any data POSTed via the API.
> So & becomes %26, + becomes %2B.

Is there a way to make it work for posting URLs?

For example, http://example.com/this+that

Using the % encoding results in the literal http://example.com/this%2Bthat,
which is incorrect and results in a 404 when clicked.

Harry

unread,
May 27, 2008, 9:21:16 PM5/27/08
to Twitter Development Talk
Nevermind, I figured out a workaround. Since urls are being shortened
anyway, I'm pre-shortening them before posting to Twitter.

Thanks for the encoding help.

Harry

Kee Hinckley

unread,
May 27, 2008, 9:21:36 PM5/27/08
to twitter-deve...@googlegroups.com
On May 27, 2008, at 8:52 PM, Harry wrote:
>
> curl -u email:pass -d status="ampersand & and plus sign +"
> http://twitter.com/statuses/update.xml
> result --> "ampersand"
> Where did the rest of the text go?


From http://groups.google.com/group/twitter-development-talk/web/api-documentation
, emphasis mine.

status. Required. The text of your status update. ***Be sure to URL
encode as necessary***. Must not be more than 160 characters and
should not be more than 140 characters to ensure optimal display.

From a quick google search for "url encoding"
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

Simon

unread,
Jun 12, 2008, 4:57:56 PM6/12/08
to Twitter Development Talk
Hi, is there any solution to the URL encoding issue with commas in
URLS being passed to the update method?

e.g. http://example.com?x=1%2c2

should result in a tinyurl link, but instead i get a broken url with a
comma at the end.

I don't have the luxury of being able to shrink the url before
posting.

Simon


On May 28, 2:08 am, Harry <harryl...@gmail.com> wrote:
> On May 27, 6:56 pm, "e.p.c." <epcoste...@gmail.com> wrote:
>
> > You have to URL encode any data POSTed via the API.
> > So & becomes %26, + becomes %2B.
>
> Is there a way to make it work for posting URLs?
>
> For example,http://example.com/this+that
>
> Using the % encoding results in the literalhttp://example.com/this%2Bthat,

Ed Costello

unread,
Jun 12, 2008, 5:28:19 PM6/12/08
to twitter-deve...@googlegroups.com
If you want the literal '%' to pass through then you might need to encode it, ie pass http://example.com?x=1%252c2.
From my experiments, updating with a status of 'http://example.com/?x=1%2c2' results in the text string "http://example.com?x=1,2" being stored by twitter.  Whatever does the linking on the web interface only links the part before the comma (http://example.com?x=1), which seems to be a bug in whatever creates the links in the web interface, not the API itself.
--
-ed costello
Reply all
Reply to author
Forward
0 new messages