Posted on Leave a comment

PHP: how to display tweets on a webpage using php?

This simple tutorial will show how to display twitter tweets using custom php.

Step 1: Download tweet-php from https://github.com/jnicol/tweet-php whereever you want.

Step2: Add following code before the section where you want to display tweets:

require_once('tweet-php/TweetPHP.php');

$TweetPHP = new TweetPHP(array(
  'consumer_key'              => 'xxxxxxxxxxxxxxxxxxxxx',
  'consumer_secret'           => 'xxxxxxxxxxxxxxxxxxxxx',
  'access_token'              => 'xxxxxxxxxxxxxxxxxxxxx',
  'access_token_secret'       => 'xxxxxxxxxxxxxxxxxxxxx',
  'twitter_screen_name'       => 'yourusername'
));

After filling above fields properly you may use can fetch details as like below:

$tweets = $TweetPHP->get_tweet_array();

foreach($tweets as $items)
    {
        echo "Time and Date of Tweet: ".$items['created_at']."<br />";
        echo "Tweet: ". $items['text']."<br />";
        echo "Tweeted by: ". $items['user']['name']."<br />";
        echo "Screen name: ". $items['user']['screen_name']."<br />";
        echo "Followers: ". $items['user']['followers_count']."<br />";
        echo "Friends: ". $items['user']['friends_count']."<br />";
        echo "Listed: ". $items['user']['listed_count']."<br />";
    }