I am trying to get all the events created on Google Calendar after a timestamp (let's say one hour ago).
I am using the Zend GData library.
If I run this code (after the initializations needed) everything works perfectly:
$query = $this->service->newEventQuery();
$query->setUser($this->getCalendarId());
$query->setVisibility('private');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setSingleevents('false');
$query->setParam('ctz', 'UTC');
$query->setMaxResults(5000);
// Retrieve the event list from the calendar server
try {
$eventFeed = $this->service->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}
But when I try to set the updated-min parameter of the query in this fashion:
$dateFormat = 'Y-m-d\TH:i:s\Z';
$query->setUpdatedMin(date($dateFormat, time()-3600));
I get this error:
Unknown authorization header
Error 401
Then, I found out something very interesting debugging the Zend Gdata library: the url that gets sent off to Google is this:
http://www.google.com:80/calendar/feeds/mywebsite.com_f7j5nudhqc8p7suju8svd2gl8s@group.calendar.google.com/private/full?orderby=starttime&singleevents=false&ctz=UTC&max-results=5000&updated-min=2011-03-14T15:17:37Z
If I turn it into this (I have only changed http:// to https://)
https://www.google.com/calendar/feeds/mywebsite.com_f7j5nudhqc8p7suju8svd2gl8s@group.calendar.google.com/private/full?orderby=starttime&singleevents=false&ctz=UTC&max-results=5000&updated-min=2011-03-14T15:17:37Z
and paste that URL in Google Chrome I get all the events updated after 2011-03-14T15:17:37Z, as I wanted.
Based on that, I thought it would be a good idea to change the content of the $scope variable in the initialization code to generate the URL for the user authentication:
$next = getCurrentUrl();
$scope = "http://www.google.com/calendar/feeds";
$secure = true;
$session = true;
// Redirect the user to the AuthSub server to sign in
$authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($next,
$scope,
$secure,
$session);
from
$scope = "http://www.google.com/calendar/feeds";
to
$scope = "https://www.google.com/calendar/feeds/";
(as documented here http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html)
But in that case, I get:
Token invalid - AuthSub token has wrong scope
I have run out of ideas after 10 hours of debugging and googling! I don't know what to do. Please any ideas or workaround is very welcome.
Thanks,
Dan