cURL包装器无法正常工作,并且未返回oauth令牌

时间:2013-10-24 09:32:18

标签: php curl twitter oauth wrapper

我正在尝试创建一个使用多用户oauth(3条腿授权)的推特应用。我在这里使用的cURL包装器不起作用,因此它不会获取请求响应并将其放入$ reqData。我无法理解为什么它不起作用。此外,当我运行此代码时,它不会返回授权所需的oauth令牌。这应该做什么?提前致谢!

<?php require_once 'OAuth.php'; 

$callback_url = "https://www.facebook.com/"; 

$consumer_key = ""; 
$consumer_secret = ""; 

$oauth_request_token = "http://twitter.com/oauth/request_token"; 
$oauth_authorize = "http://twitter.com/oauth/authorize"; 
$oauth_access_token = "http://twitter.com/oauth/access_token"; 

$sig_method = new OAuthSignatureMethod_HMAC_SHA1(); 
$test_consumer = new OAuthConsumer($consumer_key, $consumer_secret, $callback_url); 

$req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET",      $oauth_request_token);     
$req_req->sign_request($sig_method, $test_consumer, NULL); 

$oc = new OAuthCurl(); 
$reqData = $oc->fetchData($req_req->to_url()); 

parse_str($reqData['content'], $reqOAuthData); 

$req_token = new OAuthConsumer($reqOAuthData['oauth_token'],      $reqOAuthData['oauth_token_secret'], 1); 

$acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $req_token, "GET",     $oauth_authorize); 
$acc_req->sign_request($sig_method, $test_consumer, $req_token); 

$_SESSION['oauth_token'] = $reqOAuthData['oauth_token']; 
$_SESSION['oauth_token_secret'] = $reqOAuthData['oauth_token_secret']; 

Header("Location: $acc_req"); 


class OAuthCurl { 

  public function __construct() { 
  } 

  public static function fetchData($url) { 
    $options = array( 
        CURLOPT_RETURNTRANSFER => true,     // return web page 
        CURLOPT_HEADER         => false,    // don't return headers 
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects 
    ); 

    $ch = curl_init($url); 
    curl_setopt_array($ch, $options); 

    $content = curl_exec($ch); 
    $err = curl_errno($ch); 
    $errmsg = curl_error($ch); 
    $header = curl_getinfo($ch); 

    curl_close($ch); 

    $header['errno'] = $err; 
    $header['errmsg'] = $errmsg; 
    $header['content'] = $content; 
    return $header; 
  } 
} 

?>

0 个答案:

没有答案