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


PHP OAuthRequester::curl_parse方法代碼示例

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


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

示例1: requestRequestToken

 /**
  * Request a request token from the site belonging to consumer_key
  * 
  * @param string consumer_key
  * @param int usr_id
  * @param array params (optional) extra arguments for when requesting the request token
  * @param string method (optional) change the method of the request, defaults to POST (as it should be)
  * @param array options (optional) options like name and token_ttl
  * @param array curl_options	optional extra options for curl request
  * @exception OAuthException2 when no key could be fetched
  * @exception OAuthException2 when no server with consumer_key registered
  * @return array (authorize_uri, token)
  */
 static function requestRequestToken($consumer_key, $usr_id, $params = null, $method = 'POST', $options = array(), $curl_options = array())
 {
     OAuthRequestLogger::start();
     if (isset($options['token_ttl']) && is_numeric($options['token_ttl'])) {
         $params['xoauth_token_ttl'] = intval($options['token_ttl']);
     }
     $store = OAuthStore::instance();
     $r = $store->getServer($consumer_key, $usr_id);
     $uri = $r['request_token_uri'];
     $oauth = new OAuthRequester($uri, $method, $params);
     $oauth->sign($usr_id, $r);
     $text = $oauth->curl_raw($curl_options);
     if (empty($text)) {
         throw new OAuthException2('No answer from the server "' . $uri . '" while requesting a request token');
     }
     $data = $oauth->curl_parse($text);
     if ($data['code'] != 200) {
         throw new OAuthException2('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'])) {
         $opts = array();
         if (isset($options['name'])) {
             $opts['name'] = $options['name'];
         }
         if (isset($token['xoauth_token_ttl'])) {
             $opts['token_ttl'] = $token['xoauth_token_ttl'];
         }
         $store->addServerToken($consumer_key, 'request', $token['oauth_token'], $token['oauth_token_secret'], $usr_id, $opts);
     } else {
         throw new OAuthException2('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:rtoi,項目名稱:WebFramework,代碼行數:54,代碼來源:OAuthRequester.php

示例2: requestAccessToken

 /**
  * Request an access token from the site belonging to consumer_key.
  * Before this we got an request token, now we want to exchange it for
  * an access token.
  * 
  * @param string consumer_key
  * @param string token
  * @param int usr_id		user requesting the access token
  * @param string method (optional) change the method of the request, defaults to POST (as it should be)
  * @exception OAuthException when no key could be fetched
  * @exception OAuthException when no server with consumer_key registered
  */
 static function requestAccessToken($consumer_key, $token, $usr_id, $method = 'POST')
 {
     //OAuthRequestLogger::start();
     $store = OAuthStore::instance('Google');
     $r = $store->getServerTokenSecrets($consumer_key, $token, 'request', $usr_id);
     $uri = $r['access_token_uri'];
     // Delete the server request token, this one was for one use only
     $store->deleteServerToken($consumer_key, $r['token'], 0, true);
     // Try to exchange our request token for an access token
     $oauth = new OAuthRequester($uri, $method);
     //OAuthRequestLogger::setRequestObject($oauth);
     $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[$oauth->urldecode($name)] = $oauth->urldecode($value);
     }
     if (!empty($token['oauth_token']) && !empty($token['oauth_token_secret'])) {
         $store->addServerToken($consumer_key, 'access', $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();
 }
開發者ID:kamoti01,項目名稱:morsle-google,代碼行數:45,代碼來源:OAuthRequester.php


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