Problem with Zend_Oauth
Can someone checkout my code below? I'm trying to communicate with Vzaar(.com) and I cannot authorise. It looks like I'm sending the correct Authorization
header but I'm not 100%. I cannot think what else it is.
class Vzaar {
/**
*
* @var Zend_Oauth_Token_Access
*/
protected $_oAuth;
/**
*
* @var Zend_Oauth_Client
*/
protected $_oClient;
protected $_sUsername;
protected $_sSecret;
protected $_sEndPoint = 'http://vzaar.com/api/';
public functi开发者_StackOverflow社区on __construct($sUsername, $sSecret) {
$this->_sUsername = $sUsername;
$this->_sSecret = $sSecret;
$this->_oAuth = new Zend_Oauth_Token_Access();
$this->_oAuth->setToken($this->_sUsername);
$this->_oAuth->setTokenSecret($this->_sSecret);
$this->_oClient = $this->_oAuth->getHttpClient(array());
}
public function getVideos($sUsername = null) {
if (null === $sUsername) {
$sUsername = $this->_sUsername;
}
return $this->_request($sUsername . '/videos');
}
protected function _request($sUri) {
$this->_oClient->setUri($this->_sEndPoint . 'test/whoami');
$this->_oClient->setUri($this->_sEndPoint . $sUri . '.json');
$this->_oClient->prepareOauth();
Zend_Debug::dump($this->_oClient->getUri(true));
Zend_Debug::dump($this->_oClient->getHeader('Authorization'));
$oRequest = $this->_oClient->request();
Zend_Debug::dump($oRequest->getHeaders());
Zend_Debug::dump($oRequest->getRawBody());
return Zend_Json::decode($oRequest->getBody());
}
}
The problem was the API only accepted GET requests. Doh!
public function __construct($sUsername, $sSecret) {
/*** snip ***/
$this->_oClient = $this->_oAuth->getHttpClient(array(
'requestMethod' => Zend_Oauth_Client::GET
));
/*** snip ***/
}
精彩评论