A PHP class to display your singe or multiple twitter feed(s)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
css
twitter/includes
LICENSE
README.md
_config.yml
index.php
version.txt

README.md

WOW-Multi-Twitter 2.0 Class

Display Multiple Twitter Feeds on your Website

Features

  • Display optional images.
  • Caches to Disk
  • Date Styling Options
  • Uses new customised OAuth wrapper from J7mbo to get access to the API
  • Can work with single Twitter feeds too
  • Object orientated so you can have multiple separate single feeds or multiple double feeds. Currently, a maximum of 2 feeds together at a time.

Prequisites

You should already have a consumer key, consumer secret, access token and access token secret for one or both of your twitter accounts.

If not visit Twitter Apps to create them. https://apps.twitter.com/

PHP Server with CURL – The script has been tested using PHP 7 but should work for 5.6 and above.

A little knowledge of PHP and CSS are beneficial but not essential.

Installation

Unzip and copy the folder twitter and all it’s contents to your server.

On the page you want to display your twitter feed(s) load the class


  include_once 'twitter/includes/wow-multi-twitter.php';

Adding Keys and Tokens

Adding your Keys and Tokens to an array


//User 1
$consKey = '';//Add your Twitter Consumer Key here
$consSec = '';//Add your Twitter Consumer Secret here
$usrToken = '';//Add your Twitter User Token here
$usrSec ='';//Add your Twitter User Secret here

//User 2 If you only want one user, simply ommit any reference to user2
$consKey2 = '';//Add your Twitter Consumer Key here
$consSec2 = '';//Add your Twitter Consumer Secret here
$usrToken2 = '';//Add your Twitter User Token here
$usrSec2 ='';//Add your Twitter User Secret here

//Creates an array of the above keys for each user
$user1 = array($consKey,$consSec,$usrToken,$usrSec);
$user2 = array($consKey2,$consSec2,$usrToken2,$usrSec2);

Create a new instance of MultiTwitter

$twitter = new MultiTwitter();

Optional - Options

If no options are set then it will use the defaults detailed in the methods and properties section below. If you only set a few it will automatically use those from the defaults.

//Sets custom options
$options = array('maxTweets'=> 25,
 'caching_intervals' => 10,
 'display_images' =>true,
 'style'=>'ddmm'
);

$twitter->setOptions($options);

Set Users

Add our username and the key array we created earlier

//Sets the user. If you only want one user just use setUser1
$twitter->setUser1('username1',$user1);
$twitter->setUser2('username2',$user2);

Displaying the Tweets


  echo $twitter->displayTweets();

Methods and Properties

setUser1($username,$keys);

Setup authentication keys and tokens for the first user.

$username (String) Required

$keys (Array) Required

setUser2($username,$keys);

Setup authentication keys and tokens for the 2nd user, if a 2nd user is required.

$username (String) Required

$keys (Array) Required

setOptions($options);

Configure your own options

$options (Array) Optional

Default


  $defaults = array('maxTweets'=> 20,
                  'style'=>'time_since',
                  'include_retweets' => false,
                  'include_replies' => false,
                  'caching_intervals' => 60,
                  'display_images' => true
                  );

maxTweets- Default 20 (int) How many tweets you want to fetch from the Twitter Server per account.

style- default ‘time_since’ (string) Displays the date or time since format. The arguments are:

  • *‘eng_suff’ – Displays 21st February*
  • *‘ddmm’ – Displays 21 Feb*
  • *‘ddmmyy’ – Displays 21 Feb 2018*
  • *‘full_date’ – Displays Wed 21 Feb 2018*
  • *‘time_since’ – Displays the time since the tweet in hours, minutes etc.*
  • *‘month’ – Displays February 21, 2018*

include_retweets- default false(bool) Do you want to include any retweets?

include_replies- default false(bool) Do you want to include any replies?

caching_intervals- default 60(int) How often in minutes do you want to cache the JSON request?

display_images- default true(bool) Images are enabled by default but may not show on all tweets. You can optionally disable them.

displayTweets();

Output(echo) your twitter feed(s) for the world to see.

Further options including CSS styling are available on my blog: https://www.worldoweb.co.uk/2018/wow-multi-twitter-2-0-reloaded-php-class