Blog News
| Browse in : |
All
> Topics
> St.Ego's Blog
All > Topics > CMS Blog Any of these categories - All of these categories |
Twittering From Xaraya
With all of the pseudo-blog sites that are out there, it seems redundant to maintain each of them independently. Fortunately, several of them provide API's that can be used to submit updates from your own site (or MY own, in this case). If you set up an API connection for each service that you make use of, you could then publish a single article on your site and have a summary automatically posted to each of them, including links back to your primary site. Can you say "convenient"?
For now, I'll focus on the easiest one that I've found: Twitter.
Twitter runs on a continuous stream of user-submitted "status" updates. With their API, we can find a way to publish local updates on our own site and have them be replicated on Twitter. Then, you never have to go to Twitter for anything except to read the status updates of your friends. Of course, we could quickly establish a block on the site that pulled your Twitter friend updates and displayed them, but today we are only going to rig update replication...
I wanted to automatically post updates to twitter when I published them on my site. I established a new Publication Type in the Articles module to contain the submissions locally (pubtypeid 19 for me).
All it took was the following code snippet added to articles/xaradminapi/create.php, at the end, right before it returns the $aid. (it's a hack, but a quick and easy one)
if($ptid == 19) {
// Set username and password
$username = 'your_username';
$password = 'your_password';
// The message you want to send
$message = 'is twittering from Xaraya';
// 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=$title");
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';
}
}
With that in place, you too can post your Articles submissions to your Twitter account from Xaraya!
Note : Special thanks to Gareth Rushgrove for the original PHP snippet!
There are no comments attached to this item. You must be registered and logged in to post comments!
- Options:
- View Article Map
- View Archives