Understanding the API Changes
Twitter API 1.0 has been retired, and its replacement, API 1.1, requires different authentication mechanisms.
Twilio Credentials
To obtain the necessary credentials for Twitter API 1.1, follow these steps:
Simplified PHP Code
The following PHP class simplifies the process of accessing the Twitter API:
require_once('TwitterAPIExchange.php'); $settings = [ 'oauth_access_token' => 'YOUR_OAUTH_ACCESS_TOKEN', 'oauth_access_token_secret' => 'YOUR_OAUTH_ACCESS_TOKEN_SECRET', 'consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET' ]; $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; $getfield = '?screen_name=username&count=10'; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); $response = $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); $tweets = json_decode($response); foreach ($tweets as $tweet) { print_r($tweet); }
The above is the detailed content of How to Retrieve Twitter User Timeline Data Using PHP and API v1.1?. For more information, please follow other related articles on the PHP Chinese website!