8 messages in com.googlegroups.google-calendar-help-dataapiRe: PHP: getCalendarListFeed makes bl...
FromSent OnAttachments
SM15 Mar 2008 11:53 
Austin (Google)17 Mar 2008 12:00 
Austin (Google)18 Mar 2008 01:20 
SM18 Mar 2008 18:27 
SM18 Mar 2008 20:35 
Austin (Google)19 Mar 2008 11:03 
SM19 Mar 2008 18:11 
SM23 Mar 2008 12:05 
Subject:Re: PHP: getCalendarListFeed makes blank page
From:SM (sanj@gmail.com)
Date:03/23/2008 12:05:47 PM
List:com.googlegroups.google-calendar-help-dataapi

Hi Austin,

Thanks for all your help. I found the problem. The 'getCalendarFeedList()' function was indeed crashing because my web hosting company provides PHP5 without DOMDocument support configured in by default. Once I enabled this, everything works fine. It seems like the Zend Framework assumes that this functionality will be there. Perhaps future versions can do a check for such dependencies.

Anyways, thanks again for looking into my question.

Hi Austin,

It's good to know I can ignore the noise in the log file.

I'm trying to access my own calendar which has lots of stuff in it. And I have multiple calendars including imported calendars, all of which have events in them, so when I call getCalendarFeedList() I should get multiple things back. I quickly wrote a simple cgi script using the python API and successfully got a list of my calendars returned with that.

It seems that the PHP code is crashing rather than returning an empty calendar list. The reason I say this is because when my script gets to the following code, I get the "1", but not the "2" or the "3".

try { echo "1"; $calFeed = $cal->getCalendarListFeed(); echo "2";

} catch (Exception $e) { echo "3"; }

And when I look at the log file, I do see that noisy xml block that looks like the list of my calendars. So it seems like the list feed is being returned, but the function somehow stops dead right there. I can't loop through $calFeed because the script dies before executing another statement.

On Mar 19, 11:03 am, "Austin (Google)" <api.@google.com> wrote:

Hi,

Don't mind the weird encoding on the log file, I get the same thing as well.

But I did try listing out all event from the calendar you are using the following code -

function getAllEvent() {

global $gdataCal;

$url = 'http://www.google.com/calendar/feeds/default/private/full'; $query = $gdataCal->newEventQuery(); $query->setUser('p%23weather%40group.v.calendar.google.com'); $query->setVisibility('private'); $query->setProjection('full'); $query->setSingleEvents(false); $eventFeed = $gdataCal->getCalendarEventFeed($query); $logfile = 'C:\http\apps\data.log';

echo 'Event Count: ' . $eventFeed->getTotalResults() . '<br>'; echo "<ul>\n"; foreach ($eventFeed as $event) { echo "\t<li>title=" . $event->title->text; echo "<bR>id=" . $event->id->text . "\n"; echo "<br>editlink=\t" . $event->getEditLink()->href;

echo "\t\t<ul>\n"; foreach ($event->when as $when) { echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n"; } echo "\t\t</ul>\n"; echo "\t</li>\n"; } echo "</ul>\n"; }

and I got nothing back because there is no events in this calendar. So as far as I know your code is fine and works, it's just that calendar you are trying to access is empty.

Hope that helps, Austin

On Tue, Mar 18, 2008 at 8:35 PM, SM <sanj@gmail.com> wrote:

It seems like my code is dying on the call to:

calFeed = $cal->getCalendarListFeed();

I enabled debugging with:

$cal->enableRequestDebugLogging($logfile);

and I wonder if the problem is that the feed that is returned is somewhat mangled and getCalendarListFeed() is choking on that. When I look at the end of logfile, I see an xml block that seems to be the list of my calendars. However, interspersed within it are some random characters and newlines. For example, at the beginning of the block I see:

b14 <?xml version='1.0' encoding='UTF-8'?>...

Is that "b14" supposed to be there? Further into it I see another "b14" breaking up a line:

...<gd:where valueSt b14 ring=''/>...

and similarly:

<link rel='alternate' type='application/atom+xml' href='http:// www.google.com/calendar 1a2 /feeds/p%23weather%40group.v.calendar.google.com/private/full'/<http://www.google.com/calendar1a2/feeds/p%23weather%40group.v.calenda...>

Is there a reason the feed would be returned like this? Could this be breaking the call to getCalendarListFeed()?

Thanks.

On Mar 18, 1:20 am, "Austin (Google)" <api.@google.com> wrote:

Your code should works fine, try to put some code to interact with the returned feed, for example -

foreach ($calFeed as $calEntry) { echo $calEntry->getTitle()->getText(); }

If you are using the Zend Framework 1.5, there is a new feature that enabled logging (as long as you are not running with a proxy server). This is how you enable logging -

$cal = new Zend_Gdata_Calendar($client); $cal->enableRequestDebugLogging("/tmp/logfile-cal-phpcode.txt");

You can replace the file path with your preferred location.

Hope it helps, Austin

On Mon, Mar 17, 2008 at 12:00 PM, Austin (Google) <api.@google.com

wrote:

Hi,

I am thinking this is most likely a cookie issue, I don't see anything wrong with the way how you request the calendar feed. In my sample code, I am using session instead of cookie. So yea, try out my sample code to see if this is working for you -

<?php

session_start();

require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); Zend_Loader::loadClass('Zend_Gdata_App_Exception');

if (isset($_GET['token'])) {

if(! isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); }

$client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); $gCal = new Zend_Gdata_Calendar($client);

$eventFeed = $gCal->getCalendarEventFeed(); echo "<ul>\n"; foreach ($eventFeed as $event) { echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n"; echo "\t\t<ul>\n"; foreach ($event->when as $when) { echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n"; } echo "\t\t</ul>\n"; echo "\t</li>\n"; } echo "</ul>\n"; } else { $next = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; echo $next . '<br>'; $scope = 'http://www.google.com/calendar/feeds/'; $secure = false; $session = true;

$url = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);

echo "<a href=\"$url\">login to your Google account</a>";

} ?>

Hope it helps, Austin

On Sat, Mar 15, 2008 at 11:53 AM, SM <sanj@gmail.com> wrote:

The getCalendarListFeed() function doesn't seem to be working for me. I keep getting a blank page when I hit it. It doesn't throw an exception, the script just dies and outputs nothing. Can someone tell what I'm doing wrong here?...

Thank you.

<?php

// Load Zend Framework require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); Zend_Loader::loadClass('Zend_Http_Client');

// Set some globals... $g_selfURL = "http://my.domain.com/a.php"; $g_scope = "http://www.google.com/calendar/feeds/";

// Print $txt and provide a logout link on exit function mydie($txt) { exit($txt . " <hr/> <a href='/a.php?logout'>Logout</a>"); }

// Don't cache these pages header("Cache-Control: no-cache, must-revalidate"); header("Expires: Wed, 27 Mar 1996 05:00:00 GMT");

// Authenticate if (!isset($_COOKIE['cal_token'])) { if (isset($_GET['token'])) { // You can convert the single-use token to a session token $cal_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); setcookie('cal_token', $cal_token, time()+60*60*24*30); $_COOKIE['cal_token'] = $cal_token; } else { // Display link to generate single-use token $googUri = Zend_Gdata_AuthSub::getAuthSubTokenUri($g_selfURL, $g_scope, 0, 1); echo "<a href='$googUri'>Please sign in to your Google Account</ a>"; exit(); } }

// User clicked the logout link if (isset($_GET['logout'])) { Zend_Gdata_AuthSub::AuthSubRevokeToken($_COOKIE['cal_token']); setcookie('cal_token', "", time()-60*60*24*30); header("Location: $g_selfURL"); exit(); }

// Create an authenticated HTTP Client to talk to Google... try { $client = Zend_Gdata_AuthSub::getHttpClient($_COOKIE['cal_token']); } catch (Exception $e) { mydie($e->getMessage()); }

// Create a Gdata object using the authenticated Http Client... try { $cal = new Zend_Gdata_Calendar($client); } catch (Exception $e) { mydie($e->getMessage()); }

// Get a list of the user's calendars try { echo "1"; $calFeed = $cal->getCalendarListFeed(); // <-- THIS IS WHERE IT DIES echo "2"; } catch (Exception $e) { mydie($e->getMessage() ."<br/>". $e->getLine()); // <-- NO EXCEPTION IS THROWN }