Archive for the 'Programming' Category

Been busy working on a software licensing lately. Finally had the time to play with Zend’s standalone GData client library. I learnt about it through Dot Jay’s excellent article on sending SMS with Google Calendar on Twitter direct messages using PHP.

I gave it a go with his codes and realized quickEvent will not trigger a SMS alert. GCal SMS alerts are sent (latest) 5 mins before the event, creating an event now will “miss” that alert.

In other words, if you want an alert now, create an event that will occur 6 mins from now.

Translate that to code (largely from Dot Jay’s with my modifications), it looks something like this:

<?php

// Define credentials for the Google Calendar account
define(’GCAL_USER’, ‘yourid@gmail.com’);
define(’GCAL_PASS’, ‘yourpwd’);

// Include Zend GData client library
require_once ‘Zend/Loader.php’;
Zend_Loader::loadClass(’Zend_Gdata’);
Zend_Loader::loadClass(’Zend_Gdata_ClientLogin’);
Zend_Loader::loadClass(’Zend_Gdata_Calendar’);

// Get Google Calendar service name (predefined service name for calendar)
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;

// Authenticate with Google Calendar
$client = Zend_Gdata_ClientLogin::getHttpClient(GCAL_USER, GCAL_PASS, $service);

// Create a new Google Calendar object
$calendar = new Zend_Gdata_Calendar($client);

// Create a new event
$event = $calendar->newEventEntry();

//setup reminder setting
$reminder = $calendar->newReminder();
$reminder->method = “sms”;
$reminder->minutes = “5″; //google even soonest sms reminder is 5 mins

$startDate     = date(”Y-m-d”);
$startTime     = date(”H:i”, time() + 6*60);//6 mins ahead of now
$endDate     = date(”Y-m-d”);
$endTime     = date(”H:i”, time() + 7*60);//7 mins ahead of now
$tzOffset     = “+08″; //this is Singapore’s offset

$when = $calendar->newWhen();
$when->startTime = “{$startDate}T{$startTime}:00.000{$tzOffset}:00″;
$when->endTime = “{$endDate}T{$endTime}:00.000{$tzOffset}:00″;
$when->reminders = array($reminder);
$event->when = array($when);

// Add our message as the event content
$event->title = $calendar->newTitle(”My title”);
$event->content = $calendar->newContent(”TwitterSG alert”);

// Send the new event to be added to Google Calendar
if (defined(’GCAL_ID’)) {
$newEvent = $calendar->insertEvent($event, ‘http://www.google.com/calendar/feeds/’.GCAL_ID.’/private/full’);
} else {
$newEvent = $calendar->insertEvent($event);
}

?>

With this piece of code, it’s not hard to imagine the uses for it.

Related posts:



    Well as you might know that Twitter is gradually dropping SMS alerts from system to users due to high cost. GCal on the other hand still supports SMS reminders of your nearing events. I guess Google is quite rich and Twitter is not.

    I have been using Google Calendar (or GCal) static recurring events to do *ahem* some polling. Recently I was fiddling with Twitter by coding a SMS update service http://twitter.sg. It got me to wonder if we can mash the two up.

    Seems like a few people have beaten me to it. http://twittercal.com/ &
    http://dotjay.co.uk/2008/feb/php-twitter-google-calendar-sms

    As a person who is concerned with security, it bothers me since users would have to save not one but two sets of username:password into the system. This is a prevailing problem in the cyber world where users have “identities” crisis with growing adoption of online services. I digressed…

    Maybe I am still rather new to Twitter. It all seems kinda convoluted to run so many lines of code just to get a text message to a person. You might as well pick up the phone and text directly. O well… I guess I will just do that for now.

    Related posts:

      Just for fun, I bought Twitter.sg not too long ago and decided to develop a simple service to Tweet using SMS to Singapore number. Nothing as fancy as Widgeo.us but usable. Sign-up is still not live yet. Still gotta run some test…

      Related posts:
        Clicky Web Analytics