public function getConsumer($config = null) { if (!($consumer = $this->_getData('consumer'))) { if ($config === null) { $config = $this->_getConsumerConfig(); } $httpClient = new Zend_Http_Client(); $httpClient->setAdapter($this->_getAdapter()); if ($this->getTimeOut() > 0) { $httpClient->setConfig(array('timeout' => $this->getTimeOut())); } $consumer = new Zend_Oauth_Consumer($config); $consumer->setHttpClient($httpClient); $this->setData('consumer', $consumer); } return $consumer; }
public function getAccessToken($feedSID = null, $action = null, &$errors) { SJB_Session::setValue('twitterFeed', serialize($_REQUEST)); if ($feedSID != null) { $feedInfo = SJB_SocialMedia::getFeedInfoByNetworkIdAndSID(self::NETWORK_ID, $feedSID); } if ($action != 'grant') { $feedInfo['consumerKey'] = SJB_Request::getVar('consumerKey'); $feedInfo['consumerSecret'] = SJB_Request::getVar('consumerSecret'); $feedInfo['account_id'] = SJB_Request::getVar('account_id'); } $config = array('callbackUrl' => self::getCallBackUrl($feedSID, $action, SJB_Request::getVar('submit')), 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $feedInfo['consumerKey'], 'consumerSecret' => $feedInfo['consumerSecret'], 'requestTokenUrl' => 'https://api.twitter.com/oauth/request_token', 'userAuthorizationUrl' => 'https://api.twitter.com/oauth/authorize', 'accessTokenUrl' => 'https://api.twitter.com/oauth/access_token'); $consumer = new Zend_Oauth_Consumer($config); $client = new Zend_Http_Client(); $client->setConfig(array('sslcert' => 'cacert.pem')); $consumer->setHttpClient($client); $sessionTwitterRequestToken = SJB_Session::getValue('TWITTER_REQUEST_TOKEN'); if (SJB_Request::getVar('process_token', false) && !is_null($sessionTwitterRequestToken)) { $accessToken = $consumer->getAccessToken($_GET, unserialize($sessionTwitterRequestToken)); $feedInfo['access_token'] = $accessToken; $twitter = self::getZendServiceTwitter($feedInfo, $accessToken); $response = $twitter->account->accountVerifyCredentials()->toValue(); if (!empty($response->screen_name) && strtolower($response->screen_name) == strtolower($feedInfo['account_id'])) { return $accessToken; } else { $errors[] = 'Twitter account verification failed'; return false; } } else { if ($requestToken = $consumer->getRequestToken()) { SJB_Session::setValue('TWITTER_REQUEST_TOKEN', serialize($requestToken)); $consumer->redirect(); } else { $errors[] = 'Could not retrieve a valid Token. Please check "Consumer Key" and "Consumer secret"'; return false; } } }