/** Retrieve tokens (already generated elsewhere) * @access private * @return object $tokenList */ public function getTokens() { if (!($tokenList = $this->_cache->load('latestweets'))) { $tokens = new OauthTokens(); $tokenList = $tokens->fetchRow($tokens->select()->where('service = ?', 'twitterAccess')); $this->_cache->save($tokenList, 'latestweets'); } return $tokenList; }
public function getTokens() { $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); $validToken = $tokens->fetchRow($where); $this->_accessToken = unserialize($validToken->accessToken); $this->_accessSecret = unserialize($validToken->tokenSecret); $this->_accessExpiry = $validToken->expires; $this->_handle = unserialize($validToken->sessionHandle); }
/** Get the access keys for oauth * */ private function getAccessKeys() { $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); $validToken = $tokens->fetchRow($where); if (!is_null($validToken)) { $access = array('access_token' => unserialize($validToken->accessToken), 'access_token_secret' => unserialize($validToken->tokenSecret), 'access_token_expiry' => $validToken->expires, 'handle' => unserialize($validToken->sessionHandle)); return $access; } else { return false; } }
/** Set up the constructor * @param string $appid The Yahoo application ID */ public function __construct($appid) { $this->_appID = $appid; $this->_cache = Zend_Registry::get('cache'); $this->_oauth = new Pas_Yql_Oauth(); $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); $validToken = $tokens->fetchRow($where); $this->_accessToken = unserialize($validToken->accessToken); $this->_accessSecret = unserialize($validToken->tokenSecret); $this->_accessExpiry = $validToken->expires; $this->_handle = unserialize($validToken->sessionHandle); $this->_parser = new Pas_Service_Geo_Parser(); }
/** Construct the objects * */ public function __construct() { $this->_cache = Zend_Registry::get('rulercache'); $this->_oauth = new Pas_Yql_Oauth(); $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); $validToken = $tokens->fetchRow($where); $this->_accessToken = unserialize($validToken->accessToken); $this->_accessSecret = unserialize($validToken->tokenSecret); $this->_accessExpiry = $validToken->expires; $this->_handle = unserialize($validToken->sessionHandle); $this->_config = Zend_Registry::get('config'); $this->_flickrKey = $this->_config->webservice->flickr->apikey; $this->_flickrSecret = $this->_config->webservice->flickr->secret; $this->_flickrAuth = $this->_config->webservice->flickr->auth; }
/** Request a token from Yahoo * @return string $url The formed url for yahoo oauth request to be redirected to in controller. */ public function request() { $config = array('version' => '1.0', 'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 'signatureMethod' => 'HMAC-SHA1', 'callbackUrl' => self::SITEYAHOOCALLBACK, 'siteUrl' => self::OAUTHYAHOO, 'consumerKey' => $this->_consumerKey, 'consumerSecret' => $this->_consumerSecret); $tokens = new OauthTokens(); $tokenexists = $tokens->fetchRow($tokens->select()->where('service = ?', 'yahooAccess')); if (is_null($tokenexists)) { $consumer = new Zend_Oauth_Consumer($config); $token = $consumer->getRequestToken(); $session = new Zend_Session_Namespace('yahoo_oauth'); $session->token = $token->getToken(); $session->secret = $token->getTokenSecret(); $urlParams = $token->getResponse()->getBody(); $url = self::OAUTHYAHOOREQ . $urlParams; return $url; } else { throw new Pas_Yql_Exception('Token exists'); } }
/** Create the access token and save to database * */ public function access() { $config = array('callbackUrl' => self::CALLBACKURL, 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $this->_config->webservice->twitter->consumerKey, 'consumerSecret' => $this->_config->webservice->twitter->consumerSecret); $consumer = new Zend_Oauth_Consumer($config); $tokens = new OauthTokens(); $token = $tokens->fetchRow($tokens->select()->where('service = ?', 'twitterRequest')); // Get access token if (!is_null($token)) { $accessToken = $consumer->getAccessToken(Zend_Controller_Front::getInstance()->getRequest()->getQuery(), unserialize($token['accessToken'])); $oauth_token = $accessToken->getToken(); $tokenRow = $this->createRow(); $tokenRow->service = 'twitterAccess'; $tokenRow->created = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss'); $tokenRow->accessToken = serialize($accessToken); $tokenRow->save(); return true; } else { throw new Pas_Yql_Exception('Invalid access. No token provided.'); } }
/** Create the access token and save to database * */ public function access() { $config = array('requestTokenUrl' => 'http://www.flickr.com/services/oauth/request_token', 'accessTokenUrl' => 'http://www.flickr.com/services/oauth/access_token', 'userAuthorisationUrl' => 'http://www.flickr.com/services/oauth/authorize', 'localUrl' => 'http://beta.finds.org.uk/admin/oauth', 'callbackUrl' => self::CALLBACKURL, 'consumerKey' => $this->_consumerKey, 'consumerSecret' => $this->_consumerSecret, 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1'); $session = new Zend_Session_Namespace('flickr_oauth'); // build the token request based on the original token and secret $request = new Zend_Oauth_Token_Request(); $request->setToken($session->token)->setTokenSecret($session->secret); unset($session->token); unset($session->secret); $now = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss'); $date = new Zend_Date(); $consumer = new Zend_Oauth_Consumer($config); $token = $consumer->getAccessToken(Zend_Controller_Front::getInstance()->getRequest()->getQuery(), $request); $tokens = new OauthTokens(); $tokenRow = $tokens->createRow(); $tokenRow->service = 'flickrAccess'; $tokenRow->accessToken = serialize($token); $tokenRow->created = $now; $tokenRow->save(); }
public function getTotalViews($date = NULL) { $tokens = new OauthTokens(); $tokenes = $tokens->fetchRow($tokens->select()->where('service = ?', 'flickrAccess')); $instance = unserialize($tokenes->accessToken); $oauthOptions = array('requestTokenUrl' => 'http://www.flickr.com/services/oauth/request_token', 'accessTokenUrl' => 'http://www.flickr.com/services/oauth/access_token', 'userAuthorisationUrl' => 'http://www.flickr.com/services/oauth/authorize', 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1', 'consumerKey' => $this->_flickr->apikey, 'consumerSecret' => $this->_flickr->secret); $client = $instance->getHttpClient($oauthOptions); $client->setMethod(Zend_Http_Client::POST); $client->setUri(self::FLICKRURI); $client->setParameterPost('method', 'flickr.stats.getTotalViews'); $client->setParameterPost('format', 'json'); $client->setParameterPost('nojsoncallback', 1); $response = $client->request(); return json_decode($response->getBody()); }
/** List available Oauth tokens that have been generated for use. * @access public * @return void */ public function indexAction() { $tokens = new OauthTokens(); $this->view->tokens = $tokens->fetchAll(); }
/** Call Twitter service * * @return array */ private function _callTwitter() { if (!$this->getCache()->test(md5($this->getKey()))) { $tokens = new OauthTokens(); $token = $tokens->fetchRow($tokens->select()->where('service = ?', 'twitterAccess')); $twitter = new Zend_Service_Twitter(array('username' => 'findsorguk', 'accessToken' => unserialize($token->accessToken), 'oauthOptions' => array('consumerKey' => $this->getConfig()->webservice->twitter->consumerKey, 'consumerSecret' => $this->getConfig()->webservice->twitter->consumerSecret))); $tweets = $twitter->statusesUserTimeline(array('count' => $this->getCount()))->toValue(); $this->getCache()->save($tweets); } else { $tweets = $this->getCache()->load(md5($this->getKey())); } return $this->buildHtml($tweets); }
/** Delete all the expired tokens * */ private function cleanUp() { $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); $where[] = $tokens->getAdapter()->quoteInto('expires <= ?', $this->_now); $tokens->delete($where); }
/** Create the access token and save to database * @access public * @return void */ public function access() { $config = array('requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken', 'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken', 'userAuthorisationUrl' => 'https://www.google.com/accounts/OAuthAuthorizeToken', 'localUrl' => Zend_Registry::get('siteurl') . '/admin/oauth', 'callbackUrl' => $this->getCallback(), 'consumerKey' => $this->getConsumerKey(), 'consumerSecret' => $this->getConsumerSecret(), 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1'); $session = new Zend_Session_Namespace('flickr_oauth'); // build the token request based on the original token and secret $request = new Zend_Oauth_Token_Request(); $request->setToken($session->token)->setTokenSecret($session->secret); unset($session->token); unset($session->secret); $consumer = new Zend_Oauth_Consumer($config); $token = $consumer->getAccessToken(Zend_Controller_Front::getInstance()->getRequest()->getQuery(), $request); $tokens = new OauthTokens(); $tokenRow = $tokens->createRow(); $tokenRow->service = 'googleAccess'; $tokenRow->accessToken = serialize($token); $tokenRow->created = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss'); $tokenRow->save(); }
/** Get access tokens * @access public * @return object */ public function getTokens() { $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); return $tokens->fetchRow($where); }
/** Get the access keys for oauth * @access public * @return array The keys to use */ public function getAccessKeys() { $tokens = new OauthTokens(); $where = array(); $where[] = $tokens->getAdapter()->quoteInto('service = ?', 'yahooAccess'); $validToken = $tokens->fetchRow($where); Zend_Debug::dump($validToken); exit; $access = array(); if (!is_null($validToken)) { $access['access_token'] = unserialize($validToken->accessToken); $access['access_token_secret'] = unserialize($validToken->tokenSecret); $access['access_token_expiry'] = $validToken->expires; $access['handle'] = unserialize($validToken->sessionHandle); } else { throw new Pas_Exception('No oauth token available', 500); } return $access; }