Skip to main content

WOW-Multi-Twitter 2.0 Reloaded PHP Class

0

WOW-Multi-Twitter 2.0 is a PHP class that accesses single or multiple Twitter account feeds via the Twitter API using OAuth, the standard, secure way of interacting with your Twitter feeds. Version 2.0 replaces the following 2 scripts, Multi Twitter Script and Wow Twitter Single. Some of the original code has been reused but because it is object orientated it should definitely be easier to set up.

New Features

  • Display optional images.
  • 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.

Prerequisites

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.
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.

Download

Simply download, unzip and place on your web server. Be aware that it has an index.php file which would possibly overwrite your current homepage! I recommend that you rename it or simply use the code from it.

Download WOW-Multi-Twitter 2.0

How to Use

This is just a brief guide on how to use WOW Multi-Twitter 2.0. There is further documentation inside of index.php and throughout the class itself.

Once installed on your server you need to include the script in your PHP page.

Add the keys to interact with the Twitter API:

Create a new instance of class MultiTwitter:

Add our own options – See properties and methods below for more configurations:

Setup and add all of our user keys and name together:

Finally, we can display the feed(s)

Required 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

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 your twitter feed(s) for the world to see.

Styling our Tweets

There are 3 updated style sheets enclosed. Feel free to roll your own or use any of the themes as a guide. If using multiple feeds and you would like to style each individual feed differently every feed ul is given the id wow-your_username

If you are using 2 feeds combined, ie: using setUser2() it would always use the id of the first username set in setUser1()

Conclusion

Furthermore, if you would like to suggest an improvement to the code or request a new feature then please do get in touch. Although the code has been tested thoroughly it shouldn’t contain any bugs. Please feel free to report them if you do come across any.

Topics:

%d bloggers like this: