English 中文(简体)
采用php Http_request的垂直授权
原标题:twitter authorization using php Http_request

i 确实需要你的帮助。

I m 试图利用URL,从Vitatell到NOT。

我的第一项尝试是利用ock。

$fp = fsockopen("ssl://api.twitter.com", 443) or die ("unable to open socket");

之后,我将吉大港山区行动计划(POST)的头盔如下。

$auth = "oauth_callback="http%3A%2F%2Fmydomain.org%2F~myID%2Ftwt-oauth%2Fcallback.php", oauth_consumer_key="ExmfrhvgMkUmwzGKCg5FQw", oauth_nonce="da4dfa747b27d83c9bbda69452a87bee", oauth_signature="L9ucYZUfKQ%2BRkp1FQNbzEXXrl1w%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1319451330", oauth_version="1.0" ";


$msg = "POST /oauth/request_token HTTP/1.1 
";
$msg .= "Host: api.twitter.com 
";
$msg .= "Authorization: Oauth " . $auth . "
";
$msg .= "Connection:Keep-Alive 

";
$bytes = fwrite($fp, $msg);

the result was

HTTP/1.1 401 Unauthorized
Date: Mon, 24 Oct 2011 10:15:30 GMT
Server: hi
Status: 401 Unauthorized
X-Transaction: 1319451330-75511-27215
X-Frame-Options: SAMEORIGIN
Last-Modified: Mon, 24 Oct 2011 10:15:30 GMT
X-Runtime: 0.00602
Content-Type: text/html; charset=utf-8
Content-Length: 44
Pragma: no-cache
X-Content-Type-Options: nosniff
X-Revision: DEV
Expires: Tue, 31 Mar 1981 05:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
X-MID: 6301c02e82f43071b60e91cc31326d5354818c83
Set-Cookie: k=143.248.234.102.1319451330738600; path=/; expires=Mon, 31-Oct-11 10:15:30 GMT; domain=.twitter.com
Set-Cookie: guest_id=v1%3A131945133074814112; domain=.twitter.com; path=/; expires=Wed, 23-Oct-2013 22:15:30 GMT
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCL2IbTUzAToHaWQiJWEyZDlhNjMzYWJmMmNh%250ANmE2NDU1OTMyMzQ2MWY4MTkxIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--f5d5dc205f414bd74c0270e9610712ad1e04d2ee; domain=.twitter.com; path=/; HttpOnly
Vary: Accept-Encoding
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive

Failed to validate oauth signature and token

i don t know why... do i need to base64_encode or urlencode $auth? (then, how?)
value of $auth above is what i copied and pasted from log. (is it possible to have problem with quot "" ?)

i 审判Http_requestly简单,然后。

$httpReq = new HTTP_Request("https://api.twitter.com/oauth/request_token");
$httpReq->setMethod(HTTP_REQUEST_METHOD_POST);
$httpReq->addHeader("Authorization", $auth);
$res = $httpReq->sendRequest();

then, $res->getMessage() is "Failed to validate oauth signature and token" the same as the first try above.

问题是什么?

i m stuck here quite long time... really need help..

i 加入《欧洲空间法年鉴》。 i 要求取得相同结果......

  function http($url, $method, $postfields = NULL) {

//
    $this->http_info = array();
    $ci = curl_init();
    // Curl settings 
    curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
    curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ci, CURLOPT_HTTPHEADER, array( Expect: ));
    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
    curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this,  getHeader ));
    curl_setopt($ci, CURLOPT_HEADER, FALSE);

    switch ($method) {
      case  POST :
        curl_setopt($ci, CURLOPT_POST, TRUE);
        if (!empty($postfields)) {
          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
        }    
        break;
      case  DELETE :
        curl_setopt($ci, CURLOPT_CUSTOMREQUEST,  DELETE );
        if (!empty($postfields)) {
          $url = "{$url}?{$postfields}";
        }    
    }    

    curl_setopt($ci, CURLOPT_URL, $url);
    $response = curl_exec($ci);
    $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
    $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
    $this->url = $url;
    curl_close ($ci);
    //   

    return $response;
  }

  /**  
   * Get the header info to store.
   */
  function getHeader($ch, $header) {
    $i = strpos($header,  : );
    if (!empty($i)) {
      $key = str_replace( - ,  _ , strtolower(substr($header, 0, $i)));
      $value = trim(substr($header, $i + 2)); 
      $this->http_header[$key] = $value;
    }    
    return strlen($header);
  }
最佳回答

见:如果你在任何地方使用my HTTP申请类别,其中使用fsock open()-经过彻底的测试和测试(由我做)。 目前没有当地对奥乌特的支持,但你应该能够用“<条码”人工订户。 HTTPRequest:setRequestHeader()。 如果你安装了本地的<代码>HTTPRequest级,你可能需要重新命名这一类别——我最初写道,在P4HP环境下,我没有上下游支持,也没有控制已安装的延伸。

文件载于档案顶部的评论意见。

问题回答

暂无回答




相关问题
How to set response filename without forcing "save as" dialog

I am returning a stream in some response setting the appropriate content-type header. The behavior I m looking for is this: If the browser is able to render content of the given content type then it ...

Which Http redirects status code to use?

friendfeed.com uses 302. bit.ly uses 301. I had decided to use 303. Do they behave differently in terms of support by browsers ?

Does HttpWebRequest send 200 OK automatically?

Background: I am implementing Paypal IPN handler. This great article on Paypal states that I am required to send a 200 OK back to Paypal after I read the response. The processing of IPN request is ...

Java HTTPAUTH

我试图把桌面应用程序连接起来,我是同D.icio.us api @ Delicious Alan书写的,简单地向他们提供我的用户名和密码,并请他把书记上写给我......。

Finding out where curl was redirected

I m using curl to make php send an http request to some website somewhere and have set CURLOPT_FOLLOWLOCATION to 1 so that it follows redirects. How then, can I find out where it was eventually ...

热门标签