This is because the OAuth token contains a special character, precisely, |. I think there can be other characters that cause Bad URI error.
Moreover, I have found that the Bad URI only occurs with WEBRick, a webserver provided by Ruby.
Therefore, in order to fix it, I had to modify Ruby source code.
Here is what I have done:
In the file httpresponse.rb, which resides in C:/Ruby187/lib/ruby/1.8/webrick (This depends on where you installed Ruby)
Around the line 164:
# Location is a single absoluteURI.
if location = @header['location']
if @request_uri
@header['location'] = @request_uri.merge(location)
end
end
Add URI.encode() around location before @request_uri.merge()
# Location is a single absoluteURI.
if location = @header['location']
if @request_uri
@header['location'] = @request_uri.merge(URI.encode(location))
end
end
And that's it.
I'm gonna fix this in the Ruby open source project also. This will be my first open source participation, yeahhhh.