Created
April 15, 2010 20:07
-
-
Save eric/367580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- You'll need this in your <head> somewhere --> | |
<script src="http://www.google.com/jsapi" type="text/javascript"></script> | |
<script type="text/javascript"> | |
google.load("gdata", "1.x", { packages : ["calendar"] }); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Retrieve events with a date query | |
* | |
* Much of this was taken from http://code.google.com/apis/ajax/playground/#date_queries | |
* | |
*/ | |
// Obtain a reference to the 'content' div | |
var content = document.getElementById('content'); | |
// Create the calendar service object | |
var calendarService = | |
new google.gdata.calendar.CalendarService('com.appspot.interactivesampler'); | |
// The "public/full" feed is used to retrieve events from the named public | |
// calendar with full projection. | |
var feedUri = 'http://www.google.com/calendar/feeds/b878ac83tpkjckoqh1mccmsrfk%40group.calendar.google.com/public/full'; | |
// Create a CalendarEventQuery, and specify that this query is | |
// applied toward the "private/full" feed | |
var query = new google.gdata.calendar.CalendarEventQuery(feedUri); | |
// Sort by start time | |
query.setOrderBy('starttime'); | |
query.setFutureEvents(true); | |
query.setSortOrder('ascending'); | |
query.setMaxResults(1); | |
// The callback that will be called when getEventsFeed() returns feed data | |
var callback = function(root) { | |
// Obtain the array of matched CalendarEventEntry | |
var eventEntries = root.feed.getEntries(); | |
var html = ''; | |
// If there is matches for the date query | |
if (eventEntries.length > 0) { | |
var event = eventEntries[0]; | |
html += '<p><strong>Next event:</strong> ' + event.getTimes()[0].startTime + ' ' + event.getTitle().getText() + '</p>'; | |
} else { | |
// No match is found for the date query | |
html += '<p>No events are matched from the query!</p>'; | |
} | |
// Output HTML and clear 'Loading...' text | |
content.innerHTML = html; | |
}; | |
// Error handler to be invoked when getEventsFeed() produces an error | |
var handleError = function(error) { | |
content.innerHTML = '<pre>' + error + '</pre>'; | |
}; | |
// Submit the request using the calendar service object. Notice the CalendarEventQuery | |
// object is passed in place of the feed URI | |
calendarService.getEventsFeed(query, callback, handleError); | |
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
copyright (c) 2009 Google inc. | |
You are free to copy and use this sample. | |
License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license | |
--> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> | |
<title>Calendar Data API Sample</title> | |
<script src="http://www.google.com/jsapi" type="text/javascript"></script> | |
<script type="text/javascript"> | |
google.load("gdata", "1.x", { packages : ["calendar"] }); | |
</script> | |
<script type="text/javascript"> | |
function _run() { | |
/* | |
* Retrieve events with a date query | |
* | |
* Much of this was taken from http://code.google.com/apis/ajax/playground/#date_queries | |
* | |
*/ | |
// Obtain a reference to the 'content' div | |
var content = document.getElementById('content'); | |
// Create the calendar service object | |
var calendarService = | |
new google.gdata.calendar.CalendarService('com.appspot.interactivesampler'); | |
// The "public/full" feed is used to retrieve events from the named public | |
// calendar with full projection. | |
var feedUri = 'http://www.google.com/calendar/feeds/b878ac83tpkjckoqh1mccmsrfk%40group.calendar.google.com/public/full'; | |
// Create a CalendarEventQuery, and specify that this query is | |
// applied toward the "private/full" feed | |
var query = new google.gdata.calendar.CalendarEventQuery(feedUri); | |
// Sort by start time | |
query.setOrderBy('starttime'); | |
query.setFutureEvents(true); | |
query.setSortOrder('ascending'); | |
query.setMaxResults(1); | |
// The callback that will be called when getEventsFeed() returns feed data | |
var callback = function(root) { | |
// Obtain the array of matched CalendarEventEntry | |
var eventEntries = root.feed.getEntries(); | |
var html = ''; | |
// If there is matches for the date query | |
if (eventEntries.length > 0) { | |
var event = eventEntries[0]; | |
html += '<p><strong>Next event:</strong> ' + event.getTimes()[0].startTime + ' ' + event.getTitle().getText() + '</p>'; | |
} else { | |
// No match is found for the date query | |
html += '<p>No events are matched from the query!</p>'; | |
} | |
// Output HTML and clear 'Loading...' text | |
content.innerHTML = html; | |
}; | |
// Error handler to be invoked when getEventsFeed() produces an error | |
var handleError = function(error) { | |
content.innerHTML = '<pre>' + error + '</pre>'; | |
}; | |
// Submit the request using the calendar service object. Notice the CalendarEventQuery | |
// object is passed in place of the feed URI | |
calendarService.getEventsFeed(query, callback, handleError); | |
} | |
google.setOnLoadCallback(_run); | |
</script> | |
</head> | |
<body style="font-family: Arial;border: 0 none;"> | |
<div id="content" style="width:100%;height:380px">Loading...</div> | |
</body> | |
</html> | |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment