I'm stuck trying to figure out how to access the calendars other than
my default one - this seems such a fundamental thing that I'm sure I'm
going to be told to RTFM or search the group a bit harder, but
honestly I have looked hard...
I'm using the http/xml to access my calendar (can't use zend or java
for various reasons), and so far I've been able to log in, add and
delete events from my calendar.
I then created a second private calendar, but I'm not sure at which
point I need to differentiate between the calendars...
Here's my functions that I've been using so far;
function login() {
global $sessionid, $auth;
$req =
"Email=".urlencode("[EMAIL PROTECTED]")."&Passwd=XXXX&source=Company-
myApp-1&service=cl";
$header = "POST https://www.google.com/accounts/ClientLogin HTTP/1.0\r
\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.google.com', 80, $errno, $errstr, 30);
$cont = "";
if (!$fp) {
echo "$errstr ($errno)";
fwrite($log, "Failed to open HTTP connection!");
$res = "FAILED";
}
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$cont .= fgets ($fp, 1024);
}
}
$pos = strpos($cont, "Auth=");
$auth = substr($cont, $pos+5);
}
function DeleteEvent($link) {
global $sessionid, $auth;
$pos = strpos($sessionid, "gsessionid");
$ses = substr($sessionid, $pos+11);
$l = substr($link, 21)."?gsessionid=$ses";
$header = "DELETE $l HTTP/1.0\r\n";
$header .= "Content-Type: application/atom+xml\r\n";
$header .= "Content-Length: 0\r\n";
$header .= "Authorization: GoogleLogin auth=$auth\r\n\r\n";
$fp = fsockopen ('www.google.com', 80, $errno, $errstr, 30);
$content = "";
if (!$fp) {
echo "$errstr ($errno)";
fwrite($log, "Failed to open HTTP connection!");
$res = "FAILED delete event";
}
else {
fputs ($fp, $header);
while (!feof($fp)) {
$content .= fgets ($fp, 1024);
}
fclose($fp);
}
}
function AddEvent($start, $end, $title, $details) {
global $sessionid, $auth;
$title = htmlentities($title);
$details = htmlentities($detail);
$req = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://
schemas.google.com/g/2005'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>$title</title>
<content type='text'>$details</content>
<author>
<name>nik</name>
<email>[EMAIL PROTECTED]</email>
</author>
<gd:transparency value='http://schemas.google.com/g/
2005#event.opaque'></gd:transparency>
<gd:eventStatus value='http://schemas.google.com/g/
2005#event.confirmed'></gd:eventStatus>
<gd:where valueString='not set'></gd:where>
<gd:when startTime='$start"."T12:00:00.000Z'
endTime='$end"."T13:00:00.000Z'></gd:when>
</entry>
";
$header = "POST $sessionid HTTP/1.0\r\n";
$header .= "Content-Type: application/atom+xml\r\n";
$header .= "Content-Length: " . (strlen($req)+1) . "\r\n";
$header .= "Authorization: GoogleLogin auth=$auth\r\n\r\n";
$fp = fsockopen ('www.google.com', 80, $errno, $errstr, 30);
$content = "";
if (!$fp) {
echo "$errstr ($errno)";
fwrite($log, "Failed to open HTTP connection!");
$res = "FAILED";
}
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$content .= fgets ($fp, 1024);
}
fclose($fp);
}
if (strpos($content, "gsessionid")) {
$t = preg_match('/<a href=\"([^\"]*)\">(.*)<\/a>/iU', $content,
$matches);
$sessionid = substr($matches[1], 21);
}
}
$auth = "";
$sessionid = '/calendar/feeds/default/private/full';
login();
// do once to get gsessionid
AddEvent(0,0,0,0,0);
$pos = strpos($sessionid, "gsessionid");
$ses = substr($sessionid, $pos+11);
$header = "GET /calendar/feeds/moi%40gmail.com/private/full?gsessionid=
$ses&max-results=1000 HTTP/1.0\r\n";
$header .= "Content-Type: text/html; charset=UTF-8\r\n";
$header .= "Authorization: GoogleLogin auth=$auth";
$header .= "Host: www.google.com\r\n";
$header .= "Connection: Close\r\n\r\n";
$fp = fsockopen ('www.google.com', 80, $errno, $errstr, 30);
$content = "";
if (!$fp) {
echo "$errstr ($errno) failed";
}
else {
fputs ($fp, $header);
while (!feof($fp)) {
$content .= fgets ($fp, 1024);
}
}
fclose($fp);
>From then on, using the above $content I check which events need
adding or deleting against my local database
All works fine with the default database, but how do I do the same
with extra calendars that I add?
Nik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---