Using Twitter as an Alternative to Text Messaging - Using a Twitter App, Prowl, Prey Fetcher, and Some Custom PHP

My wife and I finally broke down and got the new iPhones (3GS to be exact, woohoo!), and as a result were confronted with AT&T's messaging plans. We previously used T-Mobile, and for $5/month we could both share 400 texts. What a great deal! I use very few, texting my wife mostly, and some friends, but it's probably about an 80/20 split. We almost always barely pushed this 400 amount, mostly from US sending each other back and forth notes about what to get at the store, or to communicate with each other in short messages, anything else, we did over IM, or via e-mail. AT&T's messaging is $5/month for 200 texts, and they aren't shared. So we pay $10/month to NOT share 400 text messages, the next highest amount is like 1,000 texts for $15/month or something, nothing between (my wife even mentioned this to the salesman as we were buying our iphones, and he smirked).

So I got to thinking, as many others have as well, that with all this push business working now, and many apps available that push data to the iphone now, why not try and cobble a solution to push tweets, like a text message gets pushed.

There are twitter apps that push, yes, but I can't see spending money on app that's main feature is PUSH, and that's all it pushes. I can however see using a more swiss army knife like tool, such as Prowl. Prowl is pretty much awesome. You can push any data from anything, using nothing more than some scripting knowledge. If I wanted to keep tabs on pretty much anything, with a little know how I can receive messages instantaneously to my phone via Prowl.

Recipe:

  • iPhone with OS 3.1, and push has to be working
  • At least 2 twitter accounts (1 if you don't mind sending DM's to yourself)
  • Prowl, from the App Store, it's $2.99 (one time, and well worth it)
  • Prey Fetcher - This acts as the glue between twitter, and prowl
  • Custom PHP, via some frameworks ProwlPHP, and Twitter Class
  • Webhosting service, or a computer that's always on and connected to the internet, I use our HTPC at home

Now if you are willing to live with only getting updates every 5 minutes, than ONLY using prey fetcher to glue twitter and prowl together will work just fine. Unfortunately for me to see this as a real alternative to text messaging, I needed that glue to work a little quicker. I wrote a little PHP script that checks twitter every minute (yah, I know a little excessive, but it works), and then depending on if you received a new DM or not, it pushes that DM to prowl, which then pushes to your phone.

The code that glues these two frameworks together looks like this:

include_once('twitter.php');
include_once('prowlPHP.php');
twit_push_dms('last_reply.txt', 'XXtwitterXXusernameXX', 'XXtwitterXXpasswordXX', 'XXXXXXprowlXXapiXXkeyXXXXXXXXXXXX');
function twit_push_dms($reply_file, $user, $pass, $key) {
$t = new Twitter;
$t->setUsername($user);
$t->setPassword($pass);
$prowl = new Prowl($key);
$last_reply = file($reply_file);
$data = $t->getDirectMessages(null, $last_reply[0], null);
if(array_key_exists(0,$data)){
$last_reply_id = $data[0]['id'];
$fp = fopen($reply_file , "w");
fputs($fp , $last_reply_id);
fclose($fp);
foreach(array_reverse($data) as $tweet) {
$prowl_format = $tweet['sender']['screen_name'].": ".substr($tweet['text'], 0, 50);
$prowl->push(array(
'application'=>'Twitter',
'event'=>'DM',
'description'=>$prowl_format,
'priority'=>0,
),true);
var_dump($prowl->getError()); // Optional
var_dump($prowl->getRemaining()); // Optional
var_dump(date('d m Y h:i:s', $prowl->getResetdate())); // Optional
}
}
}

To check multiple accounts in the same script, I just add another line like this:

twit_push_dms('last_reply_other_user.txt', 'XXtwitterXXusername2XX', 'XXtwitterXXpassword2XX', 'XXXXXXprowlXXapiXXkey2XXXXXXXXXXXX');

Each reply text file, twitter account, and api key needs to be unique. Technically if you wanted to push the same tweets to multiple prowl accounts, you could, but that's not how I set this up. That may be more useful, for multiple people monitoring a company twitter account, or otherwise.

Last thing you have to do is schedule a cron job (using curl, or wget) to run this php script every minute or otherwise. If you really wanted to be as up to date as possible. You could create a shell script that sleeps for a smaller interval, like 30 seconds, or 15 seconds. Crons will only run every minute, that is the smallest interval possible. You can see why I did this on my own computer, rather than my webhost, as I have much more control, and also security, as this is all behind a firewall.

This PHP script is essentially what Prey Fetcher does, except they've throttled theirs down to check every 5 minutes, understandably, with the amount of users they probably have to handle. I turn DM checking off on Prey Fetcher, since I'm doing it with this script. I also still use Prey Fetcher for mentions. It's probably un-necessary, but that's what I am doing.

We've tested this, and it works pretty well. At the 1 time cost of $2.99 for unlimited amounts of "txts", I'd say I am getting my money's worth. One thing to note is that Prowl has a limit of I think 1,000 calls in a 24 hour period. So technically that means 2,000 pushes for 2 accounts. We won't ever use that!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.