當前位置: 首頁>>代碼示例>>PHP>>正文


PHP OAuthRequester類代碼示例

本文整理匯總了PHP中OAuthRequester的典型用法代碼示例。如果您正苦於以下問題:PHP OAuthRequester類的具體用法?PHP OAuthRequester怎麽用?PHP OAuthRequester使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OAuthRequester類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: oauth3_obtain_feed

/**
 * Returns the atom feed only requires oauth3/OAuthRequester.php
 * TODO: will need to throw execptions for if user has no token, or if token no longer works... :/
 */
function oauth3_obtain_feed($user_id, $request_uri = 'https://mail.google.com/mail/feed/atom')
{
    // Do we have a token for this user???
    // if not return error print "no token found for" exit();
    // if this is a curl call you can't use global user here
    //$user_id= 5;
    //$request_uri = 'https://mail.google.com/mail/feed/atom';
    try {
        $req = new OAuthRequester($request_uri, 'GET', $params = null);
        $result = $req->doRequest($user_id);
        //throws OAuthException exception on an error
        // $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
        $feed = $result['body'];
    } catch (OAuthException $e) {
        //print "Error: $e";
    }
    // TODO: how to return whatever error it says
    // should return feed body Output while still testing
    if (empty($feed) or !empty($e)) {
        return "FALSE Error Message: {$e}";
        // print "reasons for false or error info"; // or just log the error info
    } else {
        return $feed;
    }
}
開發者ID:kamoti01,項目名稱:morsle-google,代碼行數:29,代碼來源:obtain_feed.php

示例2: douban_callback

function douban_callback()
{
    OAuthRequester::requestAccessToken(DOUBAN_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_SESSION['oauth_token']));
    $req = new OAuthRequester('http://api.douban.com/people/' . urlencode('@me'), 'get');
    $res = $req->doRequest();
    $user_data = new SimpleXMLElement($res['body']);
    $uid = array_pop(explode('/', $user_data->id));
    $auth_type = 'douban';
    $auth = R::findOne('oauth', "uid=? AND type=?", array($uid, $auth_type));
    if (!$auth) {
        $auth = R::dispense('oauth');
        $auth->uid = $uid;
        $auth->type = $auth_type;
        $encrypt_key = rand(100000, 999999);
        $auth->secret = $encrypt_key;
    } else {
        $encrypt_key = $auth->secret;
    }
    $cookie_str = sha1(implode('', array($uid, $auth_type, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $encrypt_key)));
    $expire = time() + 3600 * 24 * 365;
    setcookie('s', $cookie_str, $expire);
    setcookie('auth_type', $auth_type, $expire);
    setcookie('uid', $uid, $expire);
    $auth->setMeta('buildcommand.unique', array(array('uid', 'type')));
    $auth->setMeta('buildcommand.indexes', array('uid' => 'uid'));
    R::store($auth);
}
開發者ID:reusee,項目名稱:defphp,代碼行數:27,代碼來源:douban_oauth.php

示例3: requestRequestToken

 /**
  * Request a request token from the site belonging to consumer_key
  * 
  * @param string consumer_key
  * @param int usr_id
  * @exception OAuthException when no key could be fetched
  * @exception OAuthException when no server with consumer_key registered
  * @return array (authorize_uri, token)
  */
 static function requestRequestToken($consumer_key, $usr_id)
 {
     OAuthRequestLogger::start();
     $store = OAuthStore::instance();
     $r = $store->getServer($consumer_key);
     $uri = $r['request_token_uri'];
     $oauth = new OAuthRequester($uri, 'POST');
     $oauth->sign($usr_id, $r);
     $text = $oauth->curl_raw();
     if (empty($text)) {
         throw new OAuthException('No answer from the server "' . $uri . '" while requesting a request token');
     }
     $data = $oauth->curl_parse($text);
     if ($data['code'] != 200) {
         throw new OAuthException('Unexpected result from the server "' . $uri . '" (' . $data['code'] . ') while requesting a request token');
     }
     $token = array();
     $params = explode('&', $data['body']);
     foreach ($params as $p) {
         @(list($name, $value) = explode('=', $p, 2));
         $token[$name] = $oauth->urldecode($value);
     }
     if (!empty($token['oauth_token']) && !empty($token['oauth_token_secret'])) {
         $store->addServerToken($consumer_key, 'request', $token['oauth_token'], $token['oauth_token_secret'], $usr_id);
     } else {
         throw new OAuthException('The server "' . $uri . '" did not return the oauth_token or the oauth_token_secret');
     }
     OAuthRequestLogger::flush();
     // Now we can direct a browser to the authorize_uri
     return array('authorize_uri' => $r['authorize_uri'], 'token' => $token['oauth_token']);
 }
開發者ID:phill104,項目名稱:branches,代碼行數:40,代碼來源:OAuthRequester.php

示例4: getIdentity

 public function getIdentity($oauth_user_id)
 {
     // get twitter handle
     #$request = new OAuthRequester('http://api.twitter.com/1/account/verify_credentials.xml', 'GET');
     $request = new OAuthRequester('http://api.twitter.com/1/account/verify_credentials.json', 'GET');
     $result = $request->doRequest($oauth_user_id);
     if ($result['code'] == 200) {
         $data = json_decode($result['body'], true);
         if (is_null($data)) {
             switch (json_last_error()) {
                 case JSON_ERROR_DEPTH:
                     error_log('JSON Error: Maximum stack depth exceeded');
                     break;
                 case JSON_ERROR_CTRL_CHAR:
                     error_log('JSON Error: Unexpected control character found');
                     break;
                 case JSON_ERROR_SYNTAX:
                     error_log('JSON Error: Syntax error, malformed JSON');
                     break;
                 case JSON_ERROR_NONE:
                     error_log('JSON Error: No errors');
                     break;
             }
             return null;
         }
         if (!is_null($data) && array_key_exists('id', $data) && array_key_exists('name', $data)) {
             return $data;
         }
     }
     return null;
 }
開發者ID:russelldavis,項目名稱:UserBase,代碼行數:31,代碼來源:index.php

示例5: getResponseAPI

function getResponseAPI($userIdZyncro, $sessionid, $serviceAPI)
{
    // Init the OAuthStore
    $options = array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'server_uri' => OAUTH_HOST, 'request_token_uri' => REQUEST_TOKEN_URL, 'signature_methods' => array('HMAC-SHA1'), 'authorize_uri' => AUTHORIZE_URL, 'access_token_uri' => ACCESS_TOKEN_URL);
    // Note: do not use "Session" storage in production. Prefer a database
    // storage, such as MySQL.
    OAuthStore::instance("Session", $options);
    try {
        // get a request token
        $getRequestTokenParams = array();
        $tokenResultParams = OAuthRequester::requestRequestToken(CONSUMER_KEY, 0, $getRequestTokenParams, 'GET');
        // get an access token
        $oauthToken = $tokenResultParams['token'];
        $getAccessTokenParams = array('oauth_verifier' => $sessionid);
        OAuthRequester::requestAccessToken(CONSUMER_KEY, $oauthToken, 0, 'POST', $getAccessTokenParams);
        // make the request.
        $urlRequest = OAUTH_HOST . $serviceAPI;
        $request = new OAuthRequester($urlRequest, 'GET');
        $result = $request->doRequest(0);
        if ($result['code'] == 200) {
            return $result['body'];
        }
    } catch (OAuthException2 $e) {
    }
}
開發者ID:nachoruiz29,項目名稱:javascript-api-samples,代碼行數:25,代碼來源:zyncro_api_functions.php

示例6: SignUrl

 /**
  * Given a URL return an OAuth signed URL.  This will handle creating a timestamp and nonce
  *
  * @param string $url the unsigned url
  * @param string $method request method GET, POST, PUT, DELETE
  * @param string $key oauth key
  * @param string $secret oauth secret
  * @param array $params querystring or post parameters
  * @param string $body the body contents of the request
  * @param string $signature_method method used for signature (default = 'HMAC_SHA1')
  */
 public static function SignUrl($url, $method, $key, $secret, $params = null, $body = null, $signature_method = 'HMAC_SHA1')
 {
     $options = array('consumer_key' => $key, 'consumer_secret' => $secret);
     $params = $params ? $params : array();
     OAuthStore::instance("2Leg", $options);
     // Obtain a request object for the request we want to make
     $request = new OAuthRequester($url, $method, $params, $body);
     $sig = $request->sign($key, null, '');
     $data = $request->signatureBaseString();
     $url = substr(urldecode($data . '&oauth_signature=' . $request->calculateDataSignature($data, $secret, '', $signature_method)), strlen($method) + 1);
     $url = VerySimpleStringUtil::ReplaceFirst('&', '?', $url);
     return $url;
 }
開發者ID:hpazevedo,項目名稱:Teste-BDR,代碼行數:24,代碼來源:OAuthUtil.php

示例7: query

 function query($query)
 {
     if (preg_match("/^SELECT|^SHOW|^DESCRIBE/i", $query)) {
         $request = new OAuthRequester(URL . "?sql=" . rawurlencode($query), 'GET');
     } else {
         $request = new OAuthRequester(URL, 'POST', "sql=" . rawurlencode($query));
     }
     $result = $request->doRequest($this->user_id);
     if ($result['code'] == 200) {
         return $result['body'];
     } else {
         return null;
     }
 }
開發者ID:maza23,項目名稱:fusion-tables-client-php,代碼行數:14,代碼來源:oauth.php

示例8: query

 function query($query)
 {
     if (preg_match("/^SELECT|^SHOW|^DESCRIBE/i", $query)) {
         $request = new OAuthRequester("https://www.googleapis.com/fusiontables/v1/query?sql=" . rawurlencode($query), 'GET');
     } else {
         $request = new OAuthRequester("https://www.googleapis.com/fusiontables/v1/query", 'POST', "sql=" . rawurlencode($query));
     }
     $result = $request->doRequest($this->user_id);
     if ($result['code'] == 200) {
         return $result['body'];
     } else {
         return null;
     }
 }
開發者ID:copyfun,項目名稱:Fusion-Tables-to-HTML-Table,代碼行數:14,代碼來源:oauth.php

示例9: run_query

  public function run_query($endpoint, $params, $method="GET")
  {
    if (!$this->apiKey)
      throw new Semantics3_AuthenticationError('No API key provided.');

    if (!$this->apiSecret)
      throw new Semantics3_AuthenticationError('No API secret provided.');

    $options = array( 'consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret );
    OAuthStore::instance("2Leg", $options );
    $url = $this->apiBase.$endpoint;
    if ($method == "GET") {
      $url = $url."?q=".urlencode(json_encode($params));
      $params = null;
    }
    else {
      $params = json_encode($params);
    }

    try
    {
      switch ($method) {
        case "GET":
          $request = new OAuthRequester($url, $method, $params);
          break;
        case "POST":
          $request = new OAuthRequester($url, $method, '', $params);
          break;
        case "DELETE":
          $request = new OAuthRequester($url, $method);
          break;
        default:
          $request = new OAuthRequester($url, $method);
      }

      $result = $request->doRequest();
      return $result['body'];
    }
    catch(OAuthException2 $e)
    {
      print "\n";
      $error = $e->getMessage();
      print $error."\n";
    }

  }
開發者ID:kuroware,項目名稱:htn-scale,代碼行數:46,代碼來源:ApiConnector.php

示例10: fGetTweets

function fGetTweets($user, $limit)
{
    $options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET);
    OAuthStore::instance("2Leg", $options);
    try {
        // Obtain a request object for the request we want to make
        $request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST");
        $result = $request->doRequest(0);
        parse_str($result['body'], $params);
        // now make the request.
        $request = new OAuthRequester(TWITTER_PUBLIC_TIMELINE_API, 'GET', $params);
        $result = $request->doRequest();
        $response = $result['body'];
    } catch (OAuthException2 $e) {
        $response = "Exception" . $e->getMessage();
    }
    return $response;
}
開發者ID:bobbyearl,項目名稱:bobbyearl.github.io,代碼行數:18,代碼來源:twitter.php

示例11: getOAuthRequester

 protected function getOAuthRequester($method, $url, $params)
 {
     switch ($method) {
         case "GET":
             $request = new OAuthRequester($url, $method, $params);
             break;
         case "POST":
             $request = new OAuthRequester($url, $method, '', $params);
             break;
         case "DELETE":
             $request = new OAuthRequester($url, $method);
             break;
         default:
             $request = new OAuthRequester($url, $method);
     }
     $result = $request->doRequest();
     return $result['body'];
 }
開發者ID:ahonnecke,項目名稱:semantics3-php,代碼行數:18,代碼來源:ApiConnector.php

示例12: readTimeline

function readTimeline($user, $count)
{
    try {
        // Obtain a request object for the request we want to make
        $request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST");
        $result = $request->doRequest(0);
        parse_str($result['body'], $params);
        // now make the request.
        if ($user === false) {
            $url = TWITTER_PUBLIC_TIMELINE_API;
        } else {
            $url = TWITTER_USER_TIMELINE_API . '?screen_name=' . $user . '&count=' . $count;
        }
        $request = new OAuthRequester($url, 'GET', $params);
        $result = $request->doRequest();
        $response = $result['body'];
    } catch (OAuthException2 $e) {
        $response = "Exception" . $e->getMessage();
    }
    return $response;
}
開發者ID:bobbyearl,項目名稱:bobbyearl.github.io,代碼行數:21,代碼來源:twitter.php

示例13: index

 function index()
 {
     $options = array('consumer_key' => $this->key, 'consumer_secret' => $this->secret);
     OAuthStore::instance("2Leg", $options);
     $url = "http://api.twitter.com/1/statuses/home_timeline.format?include_entities=true";
     // this is the URL of the request
     $method = "GET";
     // you can also use POST instead
     $params = null;
     try {
         // Obtain a request object for the request we want to make
         $request = new OAuthRequester($url, $method, $params);
         // Sign the request, perform a curl request and return the results,
         // throws OAuthException2 exception on an error
         // $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
         $result = $request->doRequest();
         $response = $result['body'];
         echo $response;
     } catch (OAuthException2 $e) {
     }
 }
開發者ID:adadsa,項目名稱:sosmed,代碼行數:21,代碼來源:c_timeline.php

示例14: oauthAuthentication

 /**
  * send an api call to yotpo to authenticate and get an access token
  * @return access token
  */
 public function oauthAuthentication()
 {
     if ($this->app_key == null or $this->secret == null) {
         Mage::log('Missing app key or secret');
         return null;
     }
     $yotpo_options = array('consumer_key' => $this->app_key, 'consumer_secret' => $this->secret, 'client_id' => $this->app_key, 'client_secret' => $this->secret, 'grant_type' => 'client_credentials');
     OAuthStore::instance("2Leg", $yotpo_options);
     try {
         $request = new OAuthRequester(self::YOTPO_OAUTH_TOKEN_URL, "POST", $yotpo_options);
         if (!$request) {
             Mage::log('Failed to get token access from yotpo api');
             return null;
         }
         $result = $request->doRequest(0);
         $tokenParams = json_decode($result['body'], true);
         return $tokenParams['access_token'];
     } catch (OAuthException2 $e) {
         Mage::log('error: ' . $e);
         return null;
     }
 }
開發者ID:macosxvn,項目名稱:techheroes,代碼行數:26,代碼來源:ApiClient.php

示例15: run_query

 public function run_query($endpoint, $query_arr)
 {
     if (!$this->apiKey) {
         throw new Semantics3_AuthenticationError('No API key provided.');
     }
     if (!$this->apiSecret) {
         throw new Semantics3_AuthenticationError('No API secret provided.');
     }
     $options = array('consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret);
     OAuthStore::instance("2Leg", $options);
     $url = "https://api.semantics3.com/v1/{$endpoint}?q=" . $query_arr;
     $method = "GET";
     $params = null;
     try {
         $request = new OAuthRequester($url, $method, $params);
         $result = $request->doRequest();
         return $result['body'];
     } catch (OAuthException2 $e) {
         print "\n";
         $error = $e->getMessage();
         print $error . "\n";
     }
 }
開發者ID:kostya1017,項目名稱:our,代碼行數:23,代碼來源:ApiConnector.php


注:本文中的OAuthRequester類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。