Display Multiple Twitter Feeds on your Website
- 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.
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.
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 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);
$twitter = new MultiTwitter();
//Sets custom options
$options = array('maxTweets'=> 25,
'caching_intervals' => 10,
'display_images' =>true,
'style'=>'ddmm'
);
$twitter->setOptions($options);
//Sets the user. If you only want one user just use setUser1
$twitter->setUser1('username1',$user1);
$twitter->setUser2('username2',$user2);
echo $twitter->displayTweets();
$username (String) Required
$keys (Array) Required
Setup authentication keys and tokens for the 2nd user, if a 2nd user is required.$username (String) Required
$keys (Array) Required
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.
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