Retrieving Twitter updates with PHP
a simple PHP script based on Twitter APIs
I’ve started using Twitter a few months ago. Personally, I like the idea of easily sending short status updates, and the opportunity to integrate it into my blog or my Facebook page.
I’ve started playing around with Twitter APIs and found an interesting PHP class by Nick Beam.
I’ve used that class, basically a PHP wrapper for the the Twitter APIs, to develop a little PHP script that retrieves the last status updates from my Twitter profile. This can be integrated in virtually any website or blog using PHP, including your WordPress-powered blog.
The basic script
The script lets you define a few parameters:
- your Twitter username
- your password (in case your updates are protected)
- the number of status updates to retrieve
You can see it in action here.
Filtering status updates
After I developed this simple script, I thought of using it to send quick updates to my website, like for example “taking tha day off” or “starting a new project”.
I realized I wanted to have the opportunity to filter my Twitted updates, to choose which messages should be published on my websites and which are just personal or part of Twitter conversations.
I decided to add a simple filtering functionality to my script, so that you can add a string to your messages to identify them. For example, I’m using this features to send updates to playground.gnvpartners.net, as shown in the screenshot below.
I simply add [playground] before each message that I want to be published on that website. The string is obviously fully editable so that you can use any prefix you like.
Here’s how the PHP function call looks like:
getTwits('nicolovolpato','password',5,'playground');
where the first parameter is your Twitter username, the second one is your password (empty if your tweets are public), the third one is the number of messages to show and the last one is the string you want to use as a filter.
Anyway, I guess the best way to learn how the script works is to download the source and play with it.
Download twitter_functions.php (4 kb ZIP).
This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.

1 Comment | View
Come on, leave your feedback!