Monday, June 15, 2009

Sometimes, getting code to work comes down to trial and error.

When working on OAuth with Twitter, getting the request token from http://twitter.com/oauth/request_token worked fine. Then, putting the authorize URL, http://twitter.com/oauth/authorize, into a browser and selecting allow worked fine.

However, when trying to exchange the request token for the access token at http://twitter.com/oauth/access_token kept resulting in HTTP 500 status.

So, then I tried the same process, but with Google. Everything worked fine, so my code was probably okay.

I did a search to see if there was any known issue with Twitter OAuth. The only thing that came up was that it was disabled on April 22, 2009, which caused a bunch of posts. But it had been restored soon afterwards.

So then I started just trying stuff.

I was doing an HTTP GET, so I tried changing it to an HTTP POST, posting an empty document. Same result.

I was putting all the OAuth parameters in the Authorization header, so I moved them into the body of the POST. It worked. Strangely, getting the request token worked with the OAuth parameters in the Authorization header.

Just to try it, I tried changing back to a GET, moving the OAuth parameters into the query string. That worked too.

If the Twitter source code were available to me, I would have been able to look at it to figure out why it was failing, but it's not, so the options were trial and error, searching documentation, and getting help from Twitter. I did a bunch of looking through documentation, which didn't help. Since I got it to work with trial and error, I didn't have to contact Twitter. If trial and error didn't work at the time, I probably would have just worked on something else, since the Twitter feature wasn't something that would be needed in the next couple of months, as far as I knew.

No comments:

Post a Comment