2016-11-09 56 views
0

我正在使用此代碼來驗證用戶的Twitter帳戶。如何驗證Oauth v1和PHP

$signature = ?????? 
$curl = curl_init(); 
     curl_setopt($curl, CURLOPT_URL, 'https://api.digits.com/1.1/sdk/account.json'); 
     curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'Content-length: 0', 
      'Content-type: application/json', 
      'Authorization: ' . 'OAuth oauth_nonce="39914766530163254991478493084", oauth_timestamp="1478493084", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="' . $consumerKey . '", oauth_token="' . $oauthToken . '", oauth_signature="'.$signature.'"', 
     )); 
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
     $result = curl_exec($curl); 
     $info = curl_getinfo($curl); 
     if ($info['http_code'] == 200) { 
      $r = json_decode($result); 
//   var_dump($r->phone_number); 
//   die(); 
      if (strval($r->phone_number) == strval($phone)) { 
       // phone is equal, validate the user 
       curl_close($curl); 
       return true; 
      } else { 
       // phone is not equal 
       curl_close($curl); 
       return false; 
      } 

     } else { 
      // unable to auth the user 
      curl_close($curl); 
      return false; 
     } 

但我不知道應該用什麼來代替$簽名。我怎樣才能生成$簽名。

問候

回答

0

試試這個代碼:

$url = 'https://api.digits.com/1.1/sdk/account.json'; 
$consumerKey = 'test'; 
$consumerSecret = 'test'; 
$oAuth = new OAuth($consumerKey, $consumerSecret); 
echo $oAuth->generateSignature('GET', $url); //EYCZrp4cBizLgXcSX5ex4pYKI8g= (or something like it) 

php-oauth需要被安裝在服務器上http://us3.php.net/manual/en/oauth.installation.php