Get Latest Tweets Using PHP With Codeigniter

Get Latest Tweets Using PHP With Codeigniter

Twitter API using get Latest tweets(feeds) .

Step 1:  you should read this article understand easily Twitter Direct Messages

step 2:  PHP page write a code like
<?php
//Twitter Application Class and Keys
require_once( APPPATH . "third_party/TwitterAPIExchange.php" );
/* this class file is attached here click this link
http://lvsclasses.blogspot.in/2013/12/twitter-direct-messages-through.html*/
$settings = array(
'oauth_access_token' => "2226778816-7789896fghfjfjyOny4OUxQgtEt8AhwZNa3pWY",
'oauth_access_token_secret' => "7dshjd456sfjdsj4563BqNcJhlYb25Zl4hlOWHvGQVw",
'consumer_key' => "VIAiEdvhfhRlVQCrH2Q",
'consumer_secret' => "eXktHzHKK4564hh54446KbNkJRHyDZpjdNTjiV9uxVXRA"
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
// The request method, according to the docs, is GET, not POST
$requestMethod = 'GET';
// Set up your get string, we're using my screen name here
$getfield = '?screen_name=BarackObama&count=5';
//count it means how many latest tweets you want.
// Create the object
$twitter = new TwitterAPIExchange($settings);
// Make the request and get the response into the $json variable
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
// It's json, so decode it into an array
$result = json_decode($json);
foreach ($result as $entry) {?>
<img src="<?php echo $entry->user->profile_image_url;?>">
<?php echo $entry->text ."<br>";
}
print_r($result);
// Access the profile_image_url element in the array
//echo $result->profile_image_url;
?>
example Barak Obama latest tweets here.