Few days ago Twitter change their API to new level API v1.1 and discontinued the support of XML, Atom, and RSS and instead they’re now supporting JSON only, although they give us warning few weeks before this moved is really a pain, this force us to migrate or upgrade our code to the new API, today I’ll try to give you solution but this only apply to PHP.
- Download Twitter Oauth Library developed by Abraham
– This is the first PHP Library to support OAuth for Twitter’s REST API
- Create Twitter App at Twitter Developer site
After you’ve download and created twitter app then you’re good to go, please keep these records, you need this later to verify your authentication
This code simply displays lists of user timeline in JSON format.
If you want to display other than user_timeline then you only needs to modify
$twitter_oauth = new TwitterOAuth( CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET );
$twitter_oauth ->host = "https://api.twitter.com/1.1/"; // change the default
$twitter_oauth ->ssl_verifypeer = TRUE;
$twitter_oauth ->content_type = 'application/x-www-form-urlencoded';
$tweets = $twitter_oauth->get('http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name='.$username.'&count='.$count);
Please share if you know other from PHP library that support OAuth, that help other developers who are also looking for solution, like for Ruby, Mobile Apps and more.
Happy Coding ^_^