Getting an unexpected response trying to do oAuth


#1

I am using the Abraham WIllaism twitterOAuth library, downloaded a couple of days ago. Here’s my code:

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
switch ($connection->http_code) {
  case 200:
    $url = $connection->getAuthorizeURL($token);
    print "<script>self.location='$url';</script>";
    break;

The resulting $url here is: https://api.twitter.com/oauth/authenticate?oauth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The problem is that when I re-direct to this url, here’s what I get in response:

https://api.twitter.com %09http//acme_app/twitter/index.php?oauth_token=xxxxxxxx&oauth_verifier=xxxxxxx
where http//acme_app/twitter/index.php is my callback URL
along with a message from Firefox telling me that it cannot find the server at: api.twitter.com%20%09http

Am I doing something wrong? I check the API status, but there are no listed issues.


#2

It sounds like your oauth_callback value is being over-escaped – I’d look at the code you’re using to set the callback and verify that you’re letting the OAuth code encode it once on the request token step.


#3

(please note code in question):
If you include some statements before line #8 to print out the session as well as $request_token and $url, here’s what I get:

Array
(
[oauth_token] => xxxxxxxxx
[oauth_token_secret] => xxxxxxx
)

Array
(
[oauth_token] => xxxxxxxxx
[oauth_token_secret] => xxxxxxxxxx
[oauth_callback_confirmed] => true
)

https://api.twitter.com/oauth/authenticate?oauth_token=Axxxxxxxxxx

If I run the URL, I get the following:

https://api.twitter.com %09http//270wins.us/twitter/index.php?oauth_token=xxxxxx&oauth_verifier=xxxxx

Which is the same thing I am getting when I re-direct from the code, but in this case, I’m running the url manually, so there is no code involved, but I’m still getting this. Any ideas?


#4

What is the raw value you are sending to oauth/request_token as the oauth_callback parameter?


#5

define (‘OAUTH_CALLBACK’,‘http//acme_app/twitter/index.php’);


#6

That’s not a valid URL – URLs need to have a colon between the protocol and the slashes like “http://acme_app/twitter/index.php”