Simplest PHP example for retrieving user_timeline with Twitter API version 1.1

前端 未结 14 2495
盖世英雄少女心
盖世英雄少女心 2020-11-21 17:37

Because of the Twitter API 1.0 retirement as of June 11th 2013, the script below does not work anymore.

// Create curl resource 
$ch = curl_init(); 
// Set u         


        
14条回答
  •  死守一世寂寞
    2020-11-21 17:57

    The code pasted by Rivers is great. Thanks a lot! I'm new here and can't comment, I'd just want to answer to the question from javiervd (How would you set the screen_name and count with this approach?), as I've lost a lot of time to figure it out.

    You need to add the parameters both to the URL and to the signature creating process. Creating a signature is the article that helped me. Here is my code:

    $oauth = array(
               'screen_name' => 'DwightHoward',
               'count' => 2,
               'oauth_consumer_key' => $consumer_key,
               'oauth_nonce' => time(),
               'oauth_signature_method' => 'HMAC-SHA1',
               'oauth_token' => $oauth_access_token,
               'oauth_timestamp' => time(),
               'oauth_version' => '1.0'
             );
    
    $options = array(
                 CURLOPT_HTTPHEADER => $header,
                 //CURLOPT_POSTFIELDS => $postfields,
                 CURLOPT_HEADER => false,
                 CURLOPT_URL => $url . '?screen_name=DwightHoward&count=2',
                 CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false
               );
    

提交回复
热议问题