Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use oauth to update twitter with php4?
    primarykey
    data
    text
    <p>I'm stuck with php4 (4.3.9, specifically). I would like to update my twitter status through some php code. I've received a consumer key and a consumer secret key, and I've located a nice library that theoretically let's me use oauth with php4 [<a href="https://github.com/iamcal/lib_oauth" rel="nofollow">https://github.com/iamcal/lib_oauth</a>]. </p> <p>I can get the first handshake done - I can get twitter to return a call to <a href="https://api.twitter.com/oauth/request_token" rel="nofollow">https://api.twitter.com/oauth/request_token</a> successfully: </p> <pre><code>Array ( [url] =&gt; https://api.twitter.com/oauth/request_token [content_type] =&gt; text/html; charset=utf-8 [http_code] =&gt; 200 [header_size] =&gt; 1086 [request_size] =&gt; 375 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0.482927 [namelookup_time] =&gt; 0.022033 [connect_time] =&gt; 0.121786 [pretransfer_time] =&gt; 0.354956 [size_upload] =&gt; 0 [size_download] =&gt; 147 [speed_download] =&gt; 304 [speed_upload] =&gt; 0 [download_content_length] =&gt; 147 [upload_content_length] =&gt; 0 [starttransfer_time] =&gt; 0.482918 [redirect_time] =&gt; 0 ) cURL error number:0 cURL error: </code></pre> <p>But when I try to then do the next call, I get a 401. Any suggestions at all are appreciated; oauth seems to break my brain :( </p> <p>== Update 9/5/11 => Here's my code ==</p> <pre><code>function oauth_http_request($url, $method="POST", $postdata=null){ echo("&lt;br /&gt;============="); echo("URL="); echo("&lt;br /&gt;"); print_r($url); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // Get around error 417 //curl_setopt($ch, CURLOPT_VERBOSE, true); // Display communication with server curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $GLOBALS['oauth_http_timeout']); echo("&lt;br /&gt;===="); echo("POST DATA:"); echo("&lt;br /&gt;"); print_r($postdata); if ($method == 'GET'){ # nothing special for GETs } else if ($method == 'POST'){ curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); } else{ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); } $response = curl_exec($ch); $headers = curl_getinfo($ch); print "&lt;pre&gt;\n"; print_r(curl_getinfo($ch)); // get error info echo "\n\ncURL error number:" .curl_errno($ch); // print error info echo "\n\ncURL error:" . curl_error($ch); print "&lt;/pre&gt;\n"; echo("&lt;br /&gt;============="); echo("HEADERS="); echo("&lt;br /&gt;"); print_r($headers); // Not getting a curl response echo("&lt;br /&gt;============="); echo("RESPONSE="); echo("&lt;br /&gt;"); print_r($response); curl_close($ch); $GLOBALS['oauth_last_request'] = array( 'request' =&gt; array( 'url' =&gt; $url, 'method' =&gt; $method, 'postdata' =&gt; $postdata, ), 'headers' =&gt; $headers, 'body' =&gt; $response, ); #if ($headers['http_code'] != "200"){ #return ''; #} return $response; } </code></pre> <p>And this returns:</p> <pre><code>=============URL= https://api.twitter.com/oauth/access_token ====POST DATA: oauth_version=1.0&amp;oauth_nonce=e5b76ddf5e013fe85cd553dcc5120631&amp;oauth_timestamp=1315259833&amp;oauth_consumer_key=[REDACTED]&amp;oauth_token=vUwvbMpeqGO99vlro4zujhN892wt6BNqE07vvbUYQ&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_signature=Mvcekz1WZbCPwIl6whf7rZAr4nQ%3D Array ( [url] =&gt; https://api.twitter.com/oauth/access_token [content_type] =&gt; text/html; charset=utf-8 [http_code] =&gt; 401 [header_size] =&gt; 1061 [request_size] =&gt; 424 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0.426447 [namelookup_time] =&gt; 3.4E-05 [connect_time] =&gt; 0.093783 [pretransfer_time] =&gt; 0.311701 [size_upload] =&gt; 0 [size_download] =&gt; 1 [speed_download] =&gt; 2 [speed_upload] =&gt; 0 [download_content_length] =&gt; 1 [upload_content_length] =&gt; 0 [starttransfer_time] =&gt; 0.426437 [redirect_time] =&gt; 0 ) cURL error number:0 cURL error: </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload