& and %26


#1

I have been wrestling with this for a while and find lots of suggestions but nothing that is fruitful. Here is the problem. Let’s say I want to tweet “cats & dogs” If I pass it through to oauth for posting I get “Could not authenticate with OAuth”. My guess is the ampersand is being used as a delimiter and moves variables around in the auth and therfore I am not validated.

I read a few things about url encoding the tweet and passing that. When I do it changes & to %26 as expected and I am able to send the tweet. Great news, I get past my oauth issue!! However when I go look at my tweet I see that the tweet reads %26 and not &.

I am sure this has been talked about thousands of times but I cannot find anything that works. Any advise is appreciated.

thanks,


#2

The best way to look at it is that yes, you’ll need to encode & to %26 to include it within the status body of a message. In an OAuth signature base string, then already encoded “%26” would need to be “%25%26.”

The library or environment you are using might have some features to it that is trying to “do the right thing” for you – but actually isn’t. Perhaps when you use a raw “&” it converts it %26 for the POST body but fails to convert it to %2526 for the signature basestring. Perhaps when you send a %26 instead, it converts it to %2526 for your POST body and then %252526 for your signature base string, which would explain the encoding issue in the resultant tweet.

Identifying when there’s magic behavior going on should help you solve the problem.


#3

thanks for the reply. I want to make sure that I am understanding your post correctly. The library unfortunately is not doing any conversion, I am adding it in post integration. Assuming the request URL is:
http://api.twitter.com/1/statuses/update.xml?status=cats & dogs

Are you saying it should be converted to:
http://api.twitter.com/1/statuses/update.xml?status=cats %2526 dogs
or
http://api.twitter.com/1/statuses/update.xml?status=cats %252526 dogs

Also, please confirm that there should only be 1 % versus 2 or three depending on the correct example. I tried all three and they all showed the %.

thanks,


#4

I do not understand much of what you speak of?


#5

I guess I will track and share how my debugging progresses

It looks like the library is indeed changing status to %252526
status%3Dcats%2520%252526%2520dogs


#6

if you look at my tweets you can see that I have changed the tweet to all flavors of urlencoded but see to continue to show the %26 version.


#7

For the status “cats & dogs”:

Your POST body would have status=cats%20%26%20dogs
(the spaces get encoded to %20)

Then, within your signature basestring you would double encode each of the already-percent encoded values:

status%3Dcats%2520%2526%2520dogs

When you POST cats%20%26%20dogs the resultant tweet will simply be “cats & dogs” as intended.


#8

@episod, thanks for the patience and helping me out.

Assuming the fact that the code is posting my tweets, can I assume that the signature basestring is not an issue? Is that a fair assumption?

As I urlencode the tweet that I am passing through status you can see that I am passing cats%20%26%20dogs, however it is being received and displayed as such. You can see all of my attempts through my twitter account. Thoughts?

I am thinking at this point I may scan and replace & for and until I get more time to dink round.


#9

I have the same issue. I have my status=cats & dogs. If I directly write cats %26 dogs, I get the same text with %26 included.

I am using.

http://twitter.com/intent/tweet?text=cats%20%26%20dogs

Did anyone resolve it??

Thank you


#10