Hi, my name's Austin Chau.
I work on the Calendar Date API team.
The Calendar Data API, is the API that exposes the data of
your Google calendar account.
With the API, you can do things like creating events,
searching for events, or even create a whole new calendar
program automatically.
Today, I am going to go over how to get started using
JavaScript Client Library to talk to the Calendar Data API.
I'll also be showing a demo of the new interactive developer
guide that I developed.
This new developer guide lets you play with the code right
in the browser.
So it's a great learning tool for you to start learning how
to use the client library.
The JavaScript Client Library is the latest client library
that we have added to our list of client libraries that we
officially support, which includes Java, CSharp, PHP,
and Phython.
But the JavaScript Client Library is particularly useful,
because it allows you to easily integrate with the HTML and
there is no service side dependency.
The JavaScript Client Library also has the building
technology that allows cross- domain communication, meaning
that you can now use JavaScript to perform not only
re-operation, but also write.
Using the JavaScript Client Library, it's very easy.
I'm going to show you the few steps you need to do to set up
your code to start using it.
Step 1: You have to sign up for a developer key. You do
that by going to this website.
Step 2: You need to include the client library loader on
your website by placing this script included with
your developer key.
Step 3: You need to upload an image to the same domain where
the JavaScript Code is going to be. This image doesn't have
to be visible.
As you can see, I'm positioning it far off the page.
This is needed for cross-domain
communication purposes.
Step 4: You need to use the loader to load in the
JavaScript Client Library.
Step 5: You now need to set the callback function to be
called when the library is loaded and ready to go.
Step 6: Inside of the callback function, you first need to check if the
user has logged in.
If not, you need to redirect the user to the Google account
page to log in.
The user will then be returned back to your page when
they are authenticated.
Now you are ready to use the JavaScript Client Library to
make calls to play with the calendar data API.
Now let's go to the "Interactive Developer Guide."
You can access this by going to this address.
The interactive developer guide looks like a normal
developer guide with sample code, demonstrating the common
used cases that you can perform using the API.
But unlike the normal developer guide, you can now
modify the source code using the build-in text editor and
execute a code right out of the browser.
This is a fun and intuitive way to learn as you get to
immediately see the results of the action you just performed.
So let's take a look at some of the sample codes and we'll
try to execute it.
So let's run this sample code and see what happens.
The snippet you just executed retrieved a list of all your
calendars and printed out the titles.
You can pull up the embedded version of Google calendar to
verify that these are all the calendars that belong to you.
Now let's take a look at the code to see how this is done.
First you have to create calendar service object and you have to pass
in your application name.
Then you have to specify the "feedURL," where this request
will be sent to.
And we are using the "allcalendar" feed.
Then you have to define your callback function.
So inside a function, we are just peering through the list
of calendars you have and printing out it's title.
We are using the print function, which is a
convenience method that we provide in this
developer guide.
And then you also have to create a callback function
for your "error handling."
And now we are just outputting the error message to the
"Output" tab.
And finally, you have to submit this request to the
server by calling the "getALLCalendarsFeed" through
your calendar service object by passing your "feedURL,"
your "callback" and your "error callback."
So let's modify the code to something different.
Let's add some code to print out the time zone off
your calendar.
You can easily do that by going into a text editor
and changing the code.
And now let's run this code.
You'll see you have to count the title and the time zone
and output it.
Ok. Reading data from your calendars is fun, but its more
interesting to write data to calendars.
So let's create an event to your Google calendar account.
First you have to create a service object again.
And now you have to specify a different URL to do
event creation.
And this is the URL we are going to use, the
"private/full" URL.
And now you have to create an MDB object to represent this
new event.
And we set the title to "youtube video shoot."
To associate time with an event, you have to create a
"When object."
Then we have to set a start and end time of the
"When object" using the daytime strain.
And here we are, specifying the start time to be today
at 9:00 AM.
And we specify the stop time at today...10:00 AM.
And then we set the time to the "When object."
And then you add the "When object" to the event.
And you also have to specify the callback function to let
you know when the event is created.
And you have to specify the "error handling method" if
they are any errors happening.
And finally you have to submit this request to the server by
calling the "insert event method."
And let's run this code.
And let's take a look at this data calendar.
And there it is.
I hope you have an idea of how easy it is to use the
JavaScript Client Library.
The interactive developer guide has many other samples
that demonstrate other features of Calendar Data API.
So I encourage you to go check it out and go play with that.
For more resources, you can visit the Calendar Data API
home page on "code.google.com."
Thank you. Have fun coding.