Wednesday, September 4, 2013

Read Tweets with PHP using Twitter API


Twitter returns information in several formats (such as json, XML), Twitter information which is return in json format we will work today to read the latest status(tweets) update of user.

The url which help us to read the latest tweets(status) is something like in this format:

Below are full working code which you can use and read the status(tweets) of specific user.

require_once('twitteroauth/twitteroauth.php'); //Path to twitteroauth library
$twitteruser = "screen name";
$nooftweets= 5;
$consumerkey = "consumer key";
$consumersecret = "consumer secret";
$accesstoken = "access token";
$accesstokensecret = "access token secret";

function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$data = $connection->get("".$twitteruser."&count=".$nooftweets);
echo '<pre>';


How to read:

for($i=0; $i<=$nooftweets;$i++){
echo '
echo $data[$i]->text;
echo "

View Demo Download

No comments :

Post a Comment