0
votes

I have modified the script found here Retrieve Google Calendar events using API v3 in javascript to display a page of upcoming events over the next 30 days which summarizes each event.

I would like to create a link provided with each event summary on the above page to another page that would show more details for a specific single event.

I cannot seem to write the code that will successfully take the eventId and query the Google Calendar API to retrieve the resources for that single event.

I apologize in advance as I am trying to learn Javascript as I go so I suspect this is something rather simple that I'm stuck on.

I am of the belief that in the makeApiCall() function I would desire to change the lines that start with:

var request = gapi.client.calendar.events.list({

to:

gapi.client.load('calendar', 'v3', function () { var request = gapi.client.calendar.events.get({ 'calendarId' : userEmail, 'eventId': eventIDstr});

I can get a valid answer when using Google's APIs Explorer pages so I know I have the correct Calendar and Event IDs. Just cannot seem to apply that to the correct javascript to get the results I am looking for.

I have searched high and low for samples of javascript that will retrieve a single Event's data from Google Calendar using v3 of their API and have come up with nothing useful. Any help would be greatly appreciated.

Thanks in advance.

1

1 Answers

0
votes

Yes, you're on the right path. Use Events:get. Events provides different flavors of event resources.

HTTP request

GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events/eventId

If successful, method returns an event resource in the response body.

import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;

// ...

// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName("applicationName").build();

// Retrieve an event
Event event = service.events().get('primary', "eventId").execute();

System.out.println(event.getSummary());

You can use singleEvents=true parameter in the list request to avoid the second call. This will ask the server to do the recurring event expansion for you right away.