Create a group Twitter account
Posted: January 22, 2008 | Author: hilary | Filed under: blog | Tags: hack, social networking, twitter, web apps, web dev | 13 Comments »
Twitter rocks. It’s useful for all kinds of things, but especially for chronicling a live event as it happens, including the pre-event discussion and post-conference wrapup.
We’re very excited to be hosting NewB Camp here in Providence, RI on February 23rd. In preparation for the event, Sara created a NewBCamp Twitter account and I coded up this quick script to pull in all tweets related to the conference.
It examines all of your followers tweets for a particular phrase or tag, and then reposts those tweets containing the tag to its own timeline with the author’s name prepended. I’m running this as a cron job on my hosting account. You can see it in action here.
This is a quick hack. It has a couple of issue that I’m aware of:
- Someone has to log in and manually add followers.
- The Twitter API only returns the previous 20 friends posts, and it’s possible we might miss some if we have so many friends that the post rate exceeds 20/50 secs (our permitted API request rate).
I do hope that you find this useful for creating your own Twitter event monitor!
include("twitter.php"); // Twitter API class
// Available: http://twitter-development-talk.googlegroups.com/web/api_class.phps.txt
// configurable options
$twitter_user = "newbcamp"; // Twitter username
$twitter_pass = "passwordgoeshere"; // Twitter password
$tag = "newbcamp"; // tag for friends to use
$twitter = new Twitter($twitter_user, $twitter_pass);
$last_post = json_decode($twitter->getUserTimeline("json",$twitter_user,1), true);
$last_post = $last_post[0]['created_at']; // get the datetime stamp of the last post to the account
// get new posts from friends since last update
$friends_posts = json_decode($twitter->getFriendsTimeline("json",$twitter_user,$last_post), true);
foreach($friends_posts as $key => $post) {
if (stripos($post['text'],$tag)) { // if the tag is present
if ($post['user']['screen_name'] != $twitter_user) { // no infinite loops, please
$new_post = $post['user']['screen_name'] . ": " . $post['text'];
// post the new post to the newbcamp account with the user's name prepended
$twitter->updateStatus($new_post);
}
}
}
Update 10.16.2009: This script is basically superseded by Twitter’s lists feature. Use that instead!