Here is a discussion we had in Beta. This was posted from Emre I looked and it seems it was not put out for public to see so sorry for that we tried to get as much out as possible but few things slipped by.
Google Calendar add-on added to allow access Google Calendar API via JScript. That addon publishes the .net wrapper lib for Google Calendar API released by Google.
##Usage
function ListCalendars()
{
var service = googleCalendar.GetService('your cliend Id',' your client secret');
var list = service.CalendarList.List().Execute().Items.ToArr();
var result = '';
for (var i = 0; i < list.length; i++)
{
result += list[i].Summary+'-';
}
return result;
}
googleCalendar.GetService(id,secret)
method returns a service object. You can use this object to access API Resources.
##How to build API call methods
https://developers.google.com/google-apps/calendar/v3/reference/ documentation lists available service resources. I’ll show you how to build your API call methods with that document.
As shown on the document there is CalendarList
resource. That means I can access resource with service.CalendarList
. Clicking on it will display details.
CalendarList resource supports List()
method. To execute that method I’ll use service.CalendarList.List().Execute()
.
Clicking on it shows what it returns.
It returns calendars with Items
property. So we can call it like…
var calendars = service.CalendarList.List().Execute().Items;
In our example our method call ends with ToArr()
method. That method converts Items
collection to a JScript Array
so we can access it’s items with [x] indexers inside for loops. As a general rule you can convert any collection to an Array with that method.
I’ve added this code as a Script so I can access it with {CALL:X}
tag.
{CALL:cal.ListCalendars()}
does nothing useful. It only returns calendar names separated by minus character.
You’ll notice I’ve used Summary
property to read Calendar’s summary. CalendarList.List().Execute().Items
returns a Collection of calendarListEntry
objects. To learn what properties calendarListEntry
object have click on calendarList
link on Response page.
You can see all properties of calendarListEntry
##Creating ClientId and ClientSecret keys.
Finally you’ll need a clientId and clientSecret to be able to access Google API’s. If you never did that before visit Google Developers Console, create new app and enable Google Calendar API
from API’s section.
From Credentials section create a new OAuth Client ID and use your client Id and client secret values while calling googleCalendar.GetService()
method.
In Summary…
- Visit Google Developer Console and create a new project. https://developers.google.com/console/help/new/
- Enable Google Calendar API.
- Create OAuth Client ID and copy keys.
- Create a new script and add sample code inside. Use your keys to create service.
- Use Calendar API documentation to construct API calls. https://developers.google.com/google-apps/calendar/v3/reference/
- Use
{CALL:X}
tag to execute api calls.