I am struggling to figure this out, but with everything I do, I cannot get user information. I just get error 401 and can't figure out why. The code:
<?php class Tumblr { public function connect() { $tumblr = new ExternalExtended_Helper_Tumblr; $oauth = $tumblr->getOauthConsumer('https://mysite.com/register'); $requestToken = $oauth->getRequestToken(); $accessToken = $oauth->getAccessToken($this->_input->filter(array( 'oauth_token' => XenForo_Input::STRING, 'oauth_verifier' => XenForo_Input::STRING )), $requestToken); $user = $tumblr->retrieveUserInfo($accessToken); } } <?php class Helper_Tumblr { public static function getOauthConsumer($callbackUrl = '') { $options = XenForo_Application::getOptions(); if (!$options->tumblrAppKey || !$options->tumblrAppSecret) { return false; } return new Zend_Oauth_Consumer(array( 'callbackUrl' => $callbackUrl, 'requestTokenUrl' => 'https://www.tumblr.com/oauth/request_token', 'authorizeUrl' => 'https://www.tumblr.com/oauth/authorize', 'accessTokenUrl' => 'https://www.tumblr.com/oauth/access_token', 'consumerKey' => $options->tumblrAppKey, 'consumerSecret' => $options->tumblrAppSecret, )); } public static function getOauthClient($accessToken) { $options = XenForo_Application::getOptions(); if (!$options->tumblrAppKey || !$options->tumblrAppSecret) { return false; } $access = new Zend_Oauth_Token_Access(); $access->setToken($accessToken->getToken()); $access->setTokenSecret($accessToken->getToken()); return $access->getHttpClient(array( 'consumerKey' => $options->tumblrAppKey, 'consumerSecret' => $options->tumblrAppSecret )); } public static function retrieveUserInfo($accessToken) { $oauthClient = self::getOauthClient($accessToken); $oauthClient->setUri('http://api.tumblr.com/v2/user/info'); $response = $oauthClient->request(Zend_Http_Client::POST); if ($response->isError()) { throw new Exception("An error occurred sending request. Status code: {$response->getStatus()}"); } return $response; } }
The error occurs in the function 'retrieveUserInfo', and the dump of the object is as follows:
object(Zend_Http_Response)#280 (5) { ["version":protected] => string(3) "1.1" ["code":protected] => int(401) ["message":protected] => string(14) "Not Authorized" ["headers":protected] => array(7) { ["Server"] => string(5) "nginx" ["Date"] => string(29) "Mon, 17 Feb 2014 02:53:08 GMT" ["Content-type"] => string(31) "application/json; charset=utf-8" ["Transfer-encoding"] => string(7) "chunked" ["Connection"] => string(5) "close" ["Set-cookie"] => string(89) "tmgioct=53017993ddbda801421421421421; expires=Thu, 15-Feb-2024 02:53:07 GMT; path=/; httponly" ["P3p"] => string(46) "CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"" } ["body":protected] => string(71) "3c {"meta":{"status":401,"msg":"Not Authorized"},"response":[]} 0 "
Why am I saying that I have not logged in and that I have not done to become logged in?
Thanks!
oauth zend-framework tumblr xenforo
Rhododendron
source share