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


PHP OAuth::lastDebugInfo方法代码示例

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


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

示例1: fetch

 public function fetch($protected_resource_url, $extra_parameters = array(), $http_method = OAUTH_HTTP_METHOD_GET, array $http_headers = array(), $oauth_args = array(), $flags = 0)
 {
     $queryStr = parse_url($protected_resource_url, PHP_URL_QUERY);
     parse_str($queryStr, $queryParams);
     $normalizedUrl = preg_replace('/\\?.*/', '', $protected_resource_url);
     $signatureKeys = array('consumer_key' => $this->consumer_key, 'shared_secret' => $this->consumer_secret, 'oauth_token' => $this->token, 'oauth_secret' => $this->token_secret);
     $oauthParams = array('oauth_consumer_key' => $this->consumer_key, 'oauth_signature_method' => $this->signature_method, 'oauth_nonce' => $this->nonce ?: uniqid() . '.' . time(), 'oauth_timestamp' => $this->timestamp ?: time(), 'oauth_version' => $this->oauthVersion);
     if (!empty($this->token)) {
         $oauthParams['oauth_token'] = $this->token;
     }
     $oauthParams = array_merge($oauthParams, $oauth_args);
     $signParams = array_merge($queryParams, is_array($extra_parameters) ? $extra_parameters : array(), $oauthParams);
     $signature = $this->_generateSignature($http_method, $normalizedUrl, $signParams);
     if ($flags & self::FETCH_SIGONLY) {
         return $signature;
     }
     $requestParams = $extra_parameters;
     switch ($this->auth_type) {
         case OAUTH_AUTH_TYPE_URI:
             $requestParams = $oauthParams + $extra_parameters + array('oauth_signature' => $signature);
             break;
         case OAUTH_AUTH_TYPE_AUTHORIZATION:
             $auth = 'OAuth ';
             $oauthParams['oauth_signature'] = $signature;
             if ($this->flags & self::FETCH_SORTAUTH) {
                 ksort($oauthParams);
             }
             foreach ($oauthParams as $key => $value) {
                 $auth .= oauth_urlencode($key) . '="' . oauth_urlencode($value) . '",';
             }
             $http_headers['Authorization'] = rtrim($auth, ',');
             break;
         case OAUTH_AUTH_TYPE_FORM:
             $extra_parameters = http_build_query($oauthParams + array('oauth_signature' => $signature));
             break;
     }
     $url = $protected_resource_url;
     if (!empty($requestParams) && is_array($requestParams) && empty($queryParams)) {
         $url .= '?' . http_build_query($requestParams);
     }
     $curlHeaders = array();
     foreach ($http_headers as $name => $value) {
         $curlHeaders[] = "{$name}: {$value}";
     }
     if (!isset($http_headers['Accept']) && $this->requestEngine != OAUTH_REQENGINE_CURL) {
         $curlHeaders[] = "Accept:";
         // Prevent curl's default 'Accept: */*'
     }
     if ($http_method != 'POST') {
         $curlHeaders[] = "Expect:";
     }
     $curlOptions = array();
     if ($this->requestEngine == OAUTH_REQENGINE_CURL) {
         $curlOptions[CURLOPT_USERAGENT] = OAUTH_USER_AGENT;
     }
     $curlOptions = $curlOptions + array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, CURLOPT_RETURNTRANSFER => 1, CURLINFO_HEADER_OUT => 1, CURLOPT_HTTPHEADER => $curlHeaders, CURLOPT_CUSTOMREQUEST => $http_method, CURLOPT_HEADERFUNCTION => array($this, '_curlReceiveHeader'), CURLOPT_SSL_VERIFYPEER => $this->sslChecks & OAUTH_SSLCHECK_PEER, CURLOPT_SSL_VERIFYHOST => $this->sslChecks & OAUTH_SSLCHECK_HOST ? 2 : 0);
     if (is_string($extra_parameters)) {
         $curlOptions[CURLOPT_POSTFIELDS] = $extra_parameters;
     } elseif (is_array($extra_parameters) && !empty($extra_parameters)) {
         $curlOptions[CURLOPT_POSTFIELDS] = $this->http_build_query($extra_parameters);
     }
     $this->lastHeader = false;
     list($this->lastResponse, $this->lastResponseInfo) = $this->execCurl($url, $curlOptions);
     $responseCode = $this->lastResponseInfo['http_code'];
     if ($this->debug) {
         $this->debugInfo = array('lastResponse' => $this->lastResponse, 'lastResponseInfo' => $this->lastResponseInfo, 'lastResponseCode' => $responseCode, 'lastHeader' => $this->lastHeader);
         self::$lastDebugInfo = $this->debugInfo;
     }
     if ($responseCode > 300 && $responseCode < 304) {
         $redirectUrl = substr($this->lastResponseInfo['redirect_url'], 0, OAUTH_MAX_HEADER_LEN - 1);
         return $this->fetch($redirectUrl);
     } elseif ($responseCode < 200 || $responseCode > 209) {
         $e = new OAuthException("Invalid auth/bad request (got a {$responseCode}, expected HTTP/1.1 20X or a redirect)", $responseCode);
         $e->lastResponse = $this->lastResponse;
         $e->debugInfo = $this->lastResponseInfo;
         throw $e;
     }
     return true;
 }
开发者ID:vclayton,项目名称:unpecl-oauth,代码行数:79,代码来源:OAuth.php


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