Simplest PHP example for retrieving user_timeline with Twitter API version 1.1

前端 未结 14 2483
盖世英雄少女心
盖世英雄少女心 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 18:07

    If you have the OAuth PHP library installed, you don't have to worry about forming the request yourself.

    $oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    $oauth->setToken($access_token, $access_secret);
    
    $oauth->fetch("https://api.twitter.com/1.1/statuses/user_timeline.json");
    $twitter_data = json_decode($oauth->getLastResponse());
    
    print_r($twitter_data);
    

    For more information, check out The docs or their example. You can use pecl install oauth to get the library.

提交回复
热议问题