Flash, Mac and iPhone stuff
5 Jun
As you may have guessed from the title, this post is about two things; PHP and twitter. I’ll assume you all know what PHP is, but for people that don’t know about Twitter it is a service for friends, family, and co–workers to communicate and stay connected through the exchange of quick, frequent answers to one simple question: What are you doing?
When I first signed up many months ago, I must admit: I didn’t really get it. I couldn’t see the point in telling people what I was up to online, when I could simply tell them face to face. It seemed far too much effor to have to sign into the site to update my status. Then along came my iPhone and that all changed. I could post an update from anywhere as I always have a web connection in my pocket.
Even better, there were mashups that allowed third parties such as Wordpress and Facebook to update your Twitter status. The fact that everything was automated, seemed to make Twitter so much more fun and useful.
While doing a bit of research I came across a method of using a PHP script to update your twitter status. This immediately got me thinking about how I could implement this within a site. As I have just finished my first PHP site (www.flcodr.com), I thought it would be a good idea to integrate the two.
flCodr.com was created after years of trying to organise snippets of actionscript code. flCodr was born as a repository of code that was centralised in one location, so that everybody can access them. The difference with flCodr is that the code can be accessed from within Flash by using the flCodr panel.
flCodr is two things:
For the first time you will be able to access code directly from within Flash using a new extension, which will allow you to connect to an online repository of code snippets.
It seemed logical to post a new tweet (status update) each time a snippet was submitted to the site. This way, followers on Twitter could see what was happening on the site. I already had an RSS feed of the snippets, but the more ways for people to access data the better.
The first step was to set up a Twitter account for flCodr (www.twitter.com/flcodr) and then to get scripting the PHP code. Luckily for you I have included it below. Just cut and paste and change the username, password and message variables. This is really easy to hook up to a mySQL data source as you can echo out your message quite easily.
<?php // Set username and password $username = 'username'; $password = 'password'; // The message you want to send $message = 'is twittering from php using curl'; // The twitter API address $url = 'http://twitter.com/statuses/update.xml'; // Alternative JSON version // $url = 'http://twitter.com/statuses/update.json'; // Set up and execute the curl process $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message"); curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); $buffer = curl_exec($curl_handle); curl_close($curl_handle); // check for success or failure if (empty($buffer)) { echo 'message'; } else { echo 'success'; } ?>
Flash, Macs and Apps - thats pretty much what i'm about.
If you like what you see Digg my stories, and leave a comment. Thanks for looking
Leave a reply
You must be logged in to post a comment.