Zend_Oauth的问题

时间:2011-03-16 13:26:18

标签: php zend-framework oauth

有人可以在下面查看我的代码吗?我正在尝试与Vzaar(.com)沟通,我无法授权。看起来我正在发送正确的Authorization标题,但我不是100%。我想不出它是什么。

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 function __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());
    }

}

1 个答案:

答案 0 :(得分:2)

问题是API只接受GET请求。卫生署!

public function __construct($sUsername, $sSecret) {
    /*** snip ***/
    $this->_oClient = $this->_oAuth->getHttpClient(array(
        'requestMethod' => Zend_Oauth_Client::GET
    ));
    /*** snip ***/
}