Has anyone used the OAuth extension for PHP?


I’m having an issue with the PECL OAuth extension for PHP. My code is below:

define("TWITTER_CONSUMER_KEY", "consumer-key");
define("TWITTER_CONSUMER_SECRET", "consumer-secret");
$oauth->setToken('valid-token', 'valid-key');

Whenever I load the page this code is on, instead of producing output in my browser, my browser attempts to download a blank file with the same name as the PHP script. Anyone have any ideas? Has anyone successfully used the PECL OAuth extension with twitter?


I think thats because it is a json file. My browser also starts to download json files.


I’d agree with you, except for the fact that I’m not loading that URL in my browser.

I experience the same behavior if I try to fetch the Google homepage as well…

  1. You need to use the getLastResponse() method to get the response of your request.
  2. There is also probably a Content-Type issue here. Let’s be sure your web-server is returning the Content-Type: text/html header by using the PHP header() function.

This code is implementing these two suggestions. Try it and let us know how it goes:

header('Content-Type: text/html', true);

define(“TWITTER_CONSUMER_KEY”, “consumer-key”);
define(“TWITTER_CONSUMER_SECRET”, “consumer-secret”);
$oauth->setToken(‘valid-token’, ‘valid-key’);

$result = json_decode($oauth->getLastResponse());


header(‘Content-Type: text/html’, true);

$oauth->setToken('valid-token', 'valid-key');
$response = json_decode($oauth->getLastResponse());

$response_info = $oauth->getLastResponseInfo();
echo var_dump($response);

That’s the code I have now… the define()s are actually further up in my real file, as they are used in more than one place. Unfortunately, I’m still having the same issue.

P.S. not seeing how to do code formatting on here… :wink: