This is my code:
$key = "xxx";
$secret = "xxx";
$url = "https://oauth.withings.com/account";
$config = array(
"siteUrl" => $url,
"consumerKey" => $key,
"consumerSecret" => $secret,
"requestMethod" => "GET"
);
$consumer = new Zend_Oauth_Consumer($config);
try {
$token = $consumer->getRequestToken();
} catch (Zend_Oauth_Exception $e){
print $e;
}
And when I run this on my Mac (OSX 10.8, PHP 5.3.13, Zend 1.11.12) it works as it should.
But when I run it on my Linux server (Debian 6.0.5, PHP 5.3.3, Zend 1.10.6) it fails. The Zend documentation is very thin, but did something happen between 1.10 och 1.11 that makes the same code fail? The error message is as follows:
"exception 'Zend_Oauth_Exception' with message 'Could not retrieve a valid Token response from Token URL: '"
The error seems to suggest that no URL was sent along. Now, the "siteUrl" config option seems to be the same for Zend 1.10 and 1.11 so that can't be it, right?
When constructing the URL manually and using CURL on my Linux host, I get the correct response, so it can't be a network or blocking problem.
When changing the URL to say "/accounts" (i.e. to make it an incorrect URL), it returns HTML 404 code for both the Mac and Linux using this code.
I'm at a loss here. Anyone know how to troubleshoot this problem?
404 means not found, so the server can't serve a document for the URL, shouldn't have anything to do with auth... Auth failures should be 403. If you only get the 404 with auth on, the 404 could be on redirect... You should try Charles proxy or similar to debug the requests.
Edit I reread and see the 404 was intentional... I would still try to debug the requests
I found the exception in the code for Zend_Oauth_Http
it seems as tho the response is failing a scheme check, you might want to explicitly set the scheme.
the code:
/**
* Manages the switch from OAuth request scheme to another lower preference
* scheme during a request cycle.
*
* @param Zend_Http_Response
* @return void
* @throws Zend_Oauth_Exception if unable to retrieve valid token response
*/
protected function _assessRequestAttempt(Zend_Http_Response $response = null)
{
switch ($this->_preferredRequestScheme) {
case Zend_Oauth::REQUEST_SCHEME_HEADER:
$this->_preferredRequestScheme = Zend_Oauth::REQUEST_SCHEME_POSTBODY;
break;
case Zend_Oauth::REQUEST_SCHEME_POSTBODY:
$this->_preferredRequestScheme = Zend_Oauth::REQUEST_SCHEME_QUERYSTRING;
break;
default:
require_once 'Zend/Oauth/Exception.php';
throw new Zend_Oauth_Exception(
'Could not retrieve a valid Token response from Token URL:'
. ($response !== null
? PHP_EOL . $response->getBody()
: ' No body - check for headers')
);
}
}
Hope it helps.