My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

/**
* Uncomment this if you haven't installed the Zend Framework inside your php include path
* replace YOUR_ZF_PATH for you Zend Framework path, the directory where your Zend directory resides
*/
//ini_set('include_path',ini_get('include_path').':YOUR_ZF_PATH:');

/**
* Please define your Email and Password for Google Accounts access
*/
define('YOUR_EMAIL_FOR_GOOGLE_ACCOUNTS','');
define('YOUR_PASS_FOR_GOOGLE_ACCOUNTS','');

require_once 'Zend/Gdata.php';
require_once 'Zend/Loader.php';

//Let's enable autoload, ZF handles this nicely
Zend_Loader::registerAutoload();
$myEmail = YOUR_EMAIL_FOR_GOOGLE_ACCOUNTS;
$myPass = YOUR_PASS_FOR_GOOGLE_ACCOUNTS;

// Parameters for ClientAuth authentication
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($myEmail, $myPass, $service);


/**
* Lets create the Service instance, to interact with Google Data Api
*/
$service = new Zend_Gdata_Calendar($client);


$calendarName = 'My Calendar ZF Example';
$useCalendarFeed = FALSE;

try {
// Let's get the calendar list from Google calendar API
$listFeed= $service->getCalendarListFeed();
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}

/**
* Need to run through all the array to search for our calendar name
* @todo this is ugly to do, need to inspect for a better way to do this
*/
foreach ($listFeed as $calendar) {
if($calendar->title == $calendarName)
$useCalendarFeed = $calendar->content->src;
}

/**
* If we have not found the calendar we want to use,
* we need to create a new one
*/
if(FALSE === $useCalendarFeed)
{
$appCal = $service->newListEntry();
$appCal->title = $service->newTitle($calendarName);
$own_cal = "http://www.google.com/calendar/feeds/default/owncalendars/full";
$service->insertEvent($appCal, $own_cal);

/**
* Need to grab the Google Calendar feed again, with the newly inserted calendar
* We'll need the refreshed feed in order to get the newly added calendar ID in order
* to add the event into the created calendar
*/
try {
$listFeed= $service->getCalendarListFeed();
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}

}


?>

Change log

r2 by josedasilva on Jan 3, 2010   Diff
Adding example for Zend Framework Google
Calendar Interaction 1/2
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2208 bytes, 78 lines

File properties

svn:executable
*
Powered by Google Project Hosting