başarısız bir başka twitter OAuth cURL erişim belirteci isteği

0 Cevap php

Aşağıdaki işlevi yerine belirteci bir doğrulama hatası veriyor:

failed to validate oAuth signature and token

 function request_token()
 {
  // Set url
  $url = $this->site.$this->request_token_path; // http://api.twitter.com/oauth/request_token

  // Params to pass to twitter and create signature
     $params['oauth_consumer_key'] = $this->consumerKey;
     $params['oauth_token'] = '';
     $params['oauth_nonce'] = SHA1(time());
     $params['oauth_timestamp'] = time();
     $params['oauth_signature_method'] = $this->signatureMethod; // HMAC-SHA1;
     $params['oauth_version'] = $this->version; // 1.0
     ksort($params);

     //print "<pre>"; print_r($params); print "</pre>";

     // Create Signature
     $concatenatedParams = '';
     foreach($params as $k => $v){
      $concatenatedParams .= "{$k}={$v}&"; 
     }
     $concatenatedParams = substr($concatenatedParams,0,-1);

     $signatureBaseString = "POST&".urlencode($url)."&".urlencode($concatenatedParams);
     $params['oauth_signature'] = base64_encode(hash_hmac('SHA1', $signatureBaseString, $this->secret."&", TRUE));

  // Do cURL
  $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLINFO_HEADER_OUT, 0);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
   $exec = curl_exec ($ch);
   $info = curl_getinfo($ch);
  curl_close ($ch);

     print $exec;

    //print "<pre>"; print_r($info); print "</pre>";
 }

0 Cevap