2009年7月10日金曜日

GoogleCalendarをJavaScriptで取得

参考ページはこちら.
http://code.google.com/intl/ja/apis/calendar/docs/1.0/developers_guide_js.html


<html>
<head>
<img style="position:absolute; top: -1000px;" src="./dummy.gif">
<script type="text/javascript" src="http://www.google.com/jsapi?key=YOURKEY"></script>
<script type="text/javascript" src="./js/jquery"></script>
<script type="text/javascript">
<!--
google.load("gdata", "1");


function PRINT(src){
$("#message").html($("#message").html()+"<br>"+src);
}


$(document).ready(function(){
/* Loads the Google data JavaScript client library */

/*
* Retrieve all calendars
*/

// Create the calendar service object
var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');

// The default "allcalendars" feed is used to retrieve a list of all
// calendars (primary, secondary and subscribed) of the logged-in user
var feedUrl = 'http://www.google.com/calendar/feeds/default/allcalendars/full';

// Error handler to be invoked when getAllCalendarsFeed() produces an error
var handleError = function(error) {
PRINT(error);
}

// Submit the request using the calendar service object
calendarService.getAllCalendarsFeed(feedUrl, callback, handleError);
});


// The callback method that will be called when getAllCalendarsFeed() returns feed data
function callback(result) {
// Obtain the array of CalendarEntry
var entries = result.feed.entry;

for (var i = 0; i < entries.length; i++) {
var calendarEntry = entries[i];
var calendarTitle = calendarEntry.getTitle().getText();
PRINT('Calendar title = ' + calendarTitle);
}
}


//-->
</script>
</head>
<body>
<div id="message">
</div>
</body>

</html>

見落としやすいポイントが,

<img style="position:absolute; top: -1000px;" src="./dummy.gif">

ここで,dummy.gifというファイルを作って自分のサーバ上においておかないと認証されないらしい.

0 件のコメント: