当前位置: 首页>>代码示例>>PHP>>正文


PHP OAuth::setToken方法代码示例

本文整理汇总了PHP中OAuth::setToken方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuth::setToken方法的具体用法?PHP OAuth::setToken怎么用?PHP OAuth::setToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OAuth的用法示例。


在下文中一共展示了OAuth::setToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getUserDetailsAndLoginUser

 protected function getUserDetailsAndLoginUser()
 {
     $this->oauth->setToken($this->getSession('oauth')->token, $this->getSession('oauth')->secret);
     //fetch user datail XML
     $this->oauth->fetch(self::API_URL . "user/details");
     $user_details = $this->oauth->getLastResponse();
     $xml = simplexml_load_string($user_details);
     $user = array('id' => $xml->user['id'], 'username' => $xml->user['display_name'], 'account_created' => $xml->user['account_created'], 'img' => $xml->user->img['href'], 'changesets' => $xml->user->changesets['count'], 'traces' => $xml->user->traces['count'], 'description' => $xml->user->description, 'home_lat' => $xml->user->home['lat'], 'home_lon' => $xml->user->home['lon'], 'last_login' => date("Y-m-d H:i:s"));
     // convert xml-nodes to strings
     foreach ($user as &$val) {
         $val = strval($val);
     }
     // update db
     $row = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']);
     if ($row) {
         //better dont change usernames, we use it as primary key
         unset($user['username']);
         dibi::query('UPDATE users SET ', $user, ' WHERE id = %i', $user['id']);
     } else {
         $user['first_login'] = new DateTime();
         dibi::query('INSERT INTO users ', $user);
     }
     // load complete row from db
     $dbuser = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']);
     if ($dbuser['webpages'] != 'admin' and $dbuser['webpages'] != 'all') {
         $dbuser['webpages'] = '14' . ($dbuser['webpages'] ? ',' : '') . $dbuser['webpages'];
     }
     $this->user->login(new Identity($dbuser['username'], array($dbuser['webpages'] == 'admin' ? 'admin' : 'user'), $dbuser));
     // remove all tokens - TODO if tokens to be used, save them in DB
     $this->redirectUrl('//' . $_SERVER['HTTP_HOST'] . $this->getSession('oauth')->back_url);
 }
开发者ID:osmcz,项目名称:website,代码行数:31,代码来源:OauthPresenter.php

示例2: call

 function call($command)
 {
     session_start();
     if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
         $_SESSION['state'] = 0;
     }
     try {
         $oauth = new \OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
         $oauth->enableDebug();
         if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
             $request_token_info = $oauth->getRequestToken($this->request_url);
             $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
             $_SESSION['state'] = 1;
             header('Location: ' . $this->authorize_url . '?oauth_token=' . $request_token_info['oauth_token']);
             exit;
         } else {
             if ($_SESSION['state'] == 1) {
                 $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
                 $access_token_info = $oauth->getAccessToken($this->access_token_url);
                 error_log("acc token info " . $access_token_info, 1, "dustinmoorman@gmail.com");
                 $_SESSION['state'] = 2;
                 $_SESSION['token'] = $access_token_info['oauth_token'];
                 $_SESSION['secret'] = $access_token_info['oauth_token_secret'];
             }
         }
         $oauth->setToken($_SESSION['token'], $_SESSION['secret']);
         $oauth->fetch("{$this->api_url}{$command}");
         $json = json_decode($oauth->getLastResponse());
     } catch (\OAuthException $E) {
         return $E->lastResponse;
     }
     return $json;
 }
开发者ID:rocketcloudsolutions,项目名称:rcsoauth,代码行数:33,代码来源:Base.php

示例3: setOAuthClient

 /**
  * @param string $consumerKey
  * @param string $consumerSecret
  * @param string $accessToken
  * @param string$accessSecret
  * @return void
  * @throws Exception
  */
 public function setOAuthClient($consumerKey, $consumerSecret, $accessToken, $accessSecret)
 {
     if (!class_exists('OAuth')) {
         throw new Exception('The OAuth PHP module must be present to perform OAuth requests.', 1424003541);
     }
     $this->oAuthClient = new \OAuth($consumerKey, $consumerSecret);
     $this->oAuthClient->setToken($accessToken, $accessSecret);
 }
开发者ID:raumkreuzer,项目名称:SurfCaptain,代码行数:16,代码来源:OAuthRequest.php

示例4: connect

 protected function connect()
 {
     $this->oauth->setToken($this->token, $this->tokenSecret);
     $accessToken = $this->oauth->getAccessToken(self::URL_ACCESS . (Request::hasQuery('oauth_verifier') ? '?oauth_verifier=' . Request::getQuery('oauth_verifier') : ''));
     $this->state = self::STATE_CONNECTED;
     $this->token = $accessToken['oauth_token'];
     $this->tokenSecret = $accessToken['oauth_token_secret'];
     Session::set('Twitter_Token', $this->token);
     Session::set('Twitter_TokenSecret', $this->tokenSecret);
     Session::set('Twitter_State', $this->state);
     TwCensus::redirect('/');
 }
开发者ID:joksnet,项目名称:php-old,代码行数:12,代码来源:Twitter.php

示例5: _getOAuth

 private function _getOAuth()
 {
     $oauth = new OAuth($this->key, $this->secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
     if (isset($_SESSION['access_key']) && isset($_SESSION['access_secret'])) {
         $oauth->setToken($_SESSION['access_key'], $_SESSION['access_secret']);
     } else {
         if (isset($_SESSION['request_key']) && isset($_SESSION['request_secret'])) {
             $oauth->setToken($_SESSION['request_key'], $_SESSION['request_secret']);
         }
     }
     return $oauth;
 }
开发者ID:rdio,项目名称:rdio-php,代码行数:12,代码来源:rdio.php

示例6: call

 /**
  * Call Twitter API methods
  * 
  * @param string $method
  * @param array $accessToken
  * @param OAuth $oauth
  * @param array $params (include oauth_method = POST/GET if need to override)
  * @return string
  */
 public static function call($method, $accessToken = null, OAuth $oauth, $params = array())
 {
     $oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
     $resource = sprintf('%s/%s.json', 'https://api.twitter.com/1.1', $method);
     // POST or GET
     $method = OAUTH_HTTP_METHOD_GET;
     if (isset($params['oauth_method'])) {
         if ('POST' == strtoupper($params['oauth_method'])) {
             $method = OAUTH_HTTP_METHOD_POST;
         }
     } else {
         // If resource contains update, retweet (not retweets), filter, destroy, new, create - then POST not GET
         foreach (array('update', 'retweet/', 'filter', 'destroy', 'new', 'create') as $resourcePart) {
             if (false !== strpos($resource, $resourcePart)) {
                 $method = OAUTH_HTTP_METHOD_POST;
                 break;
             }
         }
     }
     if ($method == OAUTH_HTTP_METHOD_GET) {
         if (count($params)) {
             $resource = sprintf('%s?%s', $resource, http_build_query($params));
         }
         $params = null;
     }
     // Get back bad response if don't specify method where needs to be POST
     if ($oauth->fetch($resource, $params, $method)) {
         return $oauth->getLastResponse();
     } else {
         return null;
     }
 }
开发者ID:nixilla,项目名称:sfCacophonyPlugin,代码行数:41,代码来源:sfCacophonyTwitterSound.class.php

示例7: getUser

 /** 
  * Retrive Twitter auth data in Cookie set by Twitter JSSDK.
  * 
  * @param CakeRequest $request Request object.
  * @return mixed Either false or an object of user information of Twitter
  */
 public function getUser(CakeRequest $request)
 {
     $api = Configure::read('SocialSignIn.API.Twitter');
     // $request_token_url = 'http://api.twitter.com/oauth/request_token';
     // $access_token_url = "http://twitter.com/oauth/access_token";
     // $authorize_url="http://twitter.com/oauth/authorize";
     $session_name = $this->settings['session'];
     $s = SessionComponent::read($session_name);
     // if already authenticated, user object is stored in the session
     if (isset($s['User']) && is_object($s['User'])) {
         return $s['User'];
     }
     if (isset($request->query['oauth_token']) && isset($s['secret'])) {
         $oauth = new OAuth($this->settings['consumer_key'], $this->settings['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
         $oauth->setToken($request->query['oauth_token'], $s['secret']);
         $access_token_info = $oauth->getAccessToken($api['access_token_url']);
         if ($access_token_info['oauth_token']) {
             $oauth->setToken($access_token_info['oauth_token'], $access_token_info['oauth_token_secret']);
             $data = $oauth->fetch($api['fetch_url']);
             $user = json_decode($oauth->getLastResponse());
             return $user;
         }
     }
     return false;
 }
开发者ID:abhilashlohar,项目名称:Housingmatters,代码行数:31,代码来源:TwitterAuthenticate.php

示例8: authorize

 public static function authorize($consumer_key, $consumer_secret, $request_token, $request_secret)
 {
     $oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
     $oauth->setToken($request_token, $request_secret);
     $access_token_info = $oauth->getAccessToken(GOOGLE_OAUTH_ACCESS_TOKEN_API);
     return array("access_token" => $access_token_info["oauth_token"], "access_secret" => $access_token_info["oauth_token_secret"]);
 }
开发者ID:copyfun,项目名称:Fusion-Tables-to-HTML-Table,代码行数:7,代码来源:oauth_ext.php

示例9: getTwitterFriendIds

function getTwitterFriendIds($user)
{
    $cacheExpire = 24 * 60 * 60;
    $POD = $user->POD;
    $key = $POD->libOptions('twitter_api');
    $secret = $POD->libOptions('twitter_secret');
    $friends = array();
    if ($user->get('twitter_token')) {
        if ($user->get('twitter_list') != '' && time() - $user->get('twitter_list_generated') < $cacheExpire) {
            $twoots = json_decode($user->get('twitter_list'));
            foreach ($twoots as $f) {
                $friends[] = $f;
            }
        } else {
            try {
                $oauth = new OAuth($key, $secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
                $oauth->enableDebug();
                // This will generate debug output in your error_log
                $oauth->setToken($user->get('twitter_token'), $user->get('twitter_secret'));
                $oauth->fetch('https://twitter.com/friends/ids.json?cursor=-1&user_id=' . $user->get('twitter_id'));
                $json = json_decode($oauth->getLastResponse());
            } catch (Exception $e) {
            }
            // contains the first 5000 twitter friends
            foreach ($json->ids as $id) {
                $friends[] = $id;
            }
            $user->addMeta('twitter_list', json_encode($friends));
            $user->addMeta('twitter_list_generated', time());
        }
    }
    return $friends;
}
开发者ID:RichieDupes,项目名称:PeoplePods,代码行数:33,代码来源:methods.php

示例10: twitter_post

function twitter_post($text, $short_url)
{
    global $globals;
    if (!class_exists("OAuth")) {
        syslog(LOG_NOTICE, "Meneame: pecl/oauth is not installed");
        return;
    }
    if (!$globals['twitter_consumer_key'] || !$globals['twitter_consumer_secret'] || !$globals['twitter_token'] || !$globals['twitter_token_secret']) {
        syslog(LOG_NOTICE, "Meneame: consumer_key, consumer_secret, token, or token_secret not defined");
        return;
    }
    $maxlen = 140 - 24;
    //strlen($short_url);
    $msg = mb_substr(text_to_summary(html_entity_decode($text), $maxlen), 0, $maxlen) . ' ' . $short_url;
    $req_url = 'https://api.twitter.com/oauth/request_token';
    $acc_url = 'https://api.twitter.com/oauth/access_token';
    $authurl = 'https://api.twitter.com/oauth/authorize';
    $api_url = 'https://api.twitter.com/1.1/statuses/update.json';
    $oauth = new OAuth($globals['twitter_consumer_key'], $globals['twitter_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    $oauth->debug = 1;
    $oauth->setToken($globals['twitter_token'], $globals['twitter_token_secret']);
    $api_args = array("status" => $msg, "empty_param" => NULL);
    /* No using geo yet
    	if (isset($entry['lat'])) {
    		$api_args['lat'] = $entry['lat'];
    		$api_args['long'] = $entry['long'];
    	}
    	*/
    try {
        $oauth->fetch($api_url, $api_args, OAUTH_HTTP_METHOD_POST, array("User-Agent" => "pecl/oauth"));
    } catch (Exception $e) {
        syslog(LOG_INFO, 'Menéame, Twitter caught exception: ' . $e->getMessage() . " in " . basename(__FILE__) . "\n");
    }
}
开发者ID:brainsqueezer,项目名称:fffff,代码行数:34,代码来源:external_post.php

示例11: getTokenCredentials

 public static function getTokenCredentials()
 {
     $result = array();
     try {
         $access_token_url = \Fuel\Core\Config::get('evernote.evernote_server') . '/oauth';
         $oauth_verifier = \Fuel\Core\Session::get('oauthVerifier');
         $oauth = new \OAuth(\Fuel\Core\Config::get('evernote.consumer_key'), \Fuel\Core\Config::get('evernote.consumer_secret'));
         $request_token = \Fuel\Core\Session::get('requestToken');
         $request_token_secret = \Fuel\Core\Session::get('requestTokenSecret');
         $oauth->setToken($request_token, $request_token_secret);
         $access_token_info = $oauth->getAccessToken($access_token_url, null, $oauth_verifier);
         if ($access_token_info) {
             $result['status'] = 'success';
             $result['access_token'] = $access_token_info['oauth_token'];
             $result['access_token_secret'] = $access_token_info['oauth_token_secret'];
             $result['shard_id'] = $access_token_info['edam_shard'];
             $result['user_id'] = $access_token_info['edam_userId'];
         } else {
             $result['status'] = 'failure';
         }
     } catch (\OAuthException $e) {
         $result['status'] = 'failure';
     }
     return $result;
 }
开发者ID:rizumita,项目名称:fuel-evernote,代码行数:25,代码来源:evernote.php

示例12: REST_Request

 public function REST_Request($callbackUrl, $url, $method, $data = array())
 {
     /**
      * Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used
      */
     $callbackUrl = $callbackUrl;
     $temporaryCredentialsRequestUrl = $this->conf['magento_host'] . "/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
     $adminAuthorizationUrl = $this->conf['magento_host'] . '/admin/oauth_authorize';
     $accessTokenRequestUrl = $this->conf['magento_host'] . '/oauth/token';
     $apiUrl = $this->conf['magento_host'] . '/api/rest';
     $consumerKey = $this->conf['magentosoap_consumerKey'];
     $consumerSecret = $this->conf['magentosoap_consumerSecret'];
     $AccessToken = $this->conf["magentosoap_AccessToken"];
     $AccessSecret = $this->conf["magentosoap_AccessSecret"];
     try {
         //$_SESSION['state'] = 2;
         $authType = 2 == 2 ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
         $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
         $oauthClient->enableDebug();
         $oauthClient->disableSSLChecks();
         $oauthClient->setToken($AccessToken, $AccessSecret);
         $resourceUrl = $apiUrl . $url;
         $oauthClient->fetch($resourceUrl, $data, strtoupper($method), array("Content-Type" => "application/json", "Accept" => "*/*"));
         //$oauthClient->fetch($resourceUrl);
         $ret = json_decode($oauthClient->getLastResponse());
         $ret = array("error" => 0, "data" => $ret);
         return $ret;
     } catch (OAuthException $e) {
         $ret = array("error" => 1, "message" => "Checking quantity failed");
         return $ret;
     }
 }
开发者ID:tedicela,项目名称:phpmagentoapi,代码行数:32,代码来源:MagentoApi.lib.php

示例13: authorize

 function authorize()
 {
     $oauth = new OAuth(Config::get('TWITTER_CONSUMER_KEY'), Config::get('TWITTER_CONSUMER_SECRET'), OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $oauth->enableDebug();
     try {
         $request_token = $oauth->getRequestToken($this->request_token_url);
     } catch (OAuthException $e) {
         debug($oauth->debugInfo);
     }
     $url = $this->authorize_url . '?' . http_build_query(array('oauth_token' => $request_token['oauth_token'], 'callback_url'));
     print 'Authorize: ' . $url . "\n";
     system(sprintf('open %s', escapeshellarg($url)));
     fwrite(STDOUT, "Enter the PIN: ");
     $verifier = trim(fgets(STDIN));
     //$oauth->setToken($token, $request_token['oauth_token_secret']);
     //$access_token = $oauth->getAccessToken($this->access_token_url);
     $oauth->setToken($request_token['oauth_token'], $request_token['oauth_token_secret']);
     try {
         $access_token = $oauth->getAccessToken($this->access_token_url, NULL, $verifier);
     } catch (OAuthException $e) {
         debug($oauth->debugInfo);
     }
     printf("'TWITTER_TOKEN' => '%s',\n'TWITTER_TOKEN_SECRET' => '%s',\n", $access_token['oauth_token'], $access_token['oauth_token_secret']);
     exit;
 }
开发者ID:hubgit,项目名称:libapi,代码行数:25,代码来源:Twitter.php

示例14: getAccessToken

 public function getAccessToken($oauthToken, $oauthTokenSecret, $oauthVerifier)
 {
     $oauth = new \OAuth($this->consumerKey, $this->consumerSecret);
     $oauth->setToken($oauthToken, $oauthTokenSecret);
     $accessToken = $oauth->getAccessToken($this->getEndpoint('oauth'), null, $oauthVerifier);
     $this->token = $accessToken['oauth_token'];
     return $accessToken;
 }
开发者ID:slowmotion,项目名称:readerself,代码行数:8,代码来源:Client.php

示例15: getUserInfo

function getUserInfo($token, $secret)
{
    $oauth = new OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    $oauth->setToken($token, $secret);
    $oauth->fetch('http://twitter.com/account/verify_credentials.json');
    $buf = $oauth->getLastResponse();
    return json_decode($buf, true);
}
开发者ID:napthats,项目名称:rtter_js_php,代码行数:8,代码来源:connect.php


注:本文中的OAuth::setToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。