I have followed following tutorial to fetch events from google calendar which is working fine. https://developers.google.com/google-apps/calendar/quickstart/ios
Now I am stuck in insert event from my iOS app so that it can be synced with web as well. Please guide me in the right direction or post some sample code.
I am using this code for authorization in viewDidLoad
// Initialize the Google Calendar API service & load existing credentials from the keychain if available.
self.service = [[GTLServiceCalendar alloc] init];
self.service.authorizer =
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:kClientSecret];
Authorization seems fine because fetch events is working perfectly fine. But I am using following code to add an event
- (void)addAnEvent {
// Make a new event, and show it to the user to edit
GTLCalendarEvent *newEvent = [GTLCalendarEvent object];
newEvent.summary = @"Sample Added Event";
newEvent.descriptionProperty = @"Description of sample added event";
// We'll set the start time to now, and the end time to an hour from now,
// with a reminder 10 minutes before
NSDate *anHourFromNow = [NSDate dateWithTimeIntervalSinceNow:60*60];
GTLDateTime *startDateTime = [GTLDateTime dateTimeWithDate:[NSDate date]
timeZone:[NSTimeZone systemTimeZone]];
GTLDateTime *endDateTime = [GTLDateTime dateTimeWithDate:anHourFromNow
timeZone:[NSTimeZone systemTimeZone]];
newEvent.start = [GTLCalendarEventDateTime object];
newEvent.start.dateTime = startDateTime;
newEvent.end = [GTLCalendarEventDateTime object];
newEvent.end.dateTime = endDateTime;
GTLCalendarEventReminder *reminder = [GTLCalendarEventReminder object];
reminder.minutes = [NSNumber numberWithInteger:10];
reminder.method = @"email";
newEvent.reminders = [GTLCalendarEventReminders object];
newEvent.reminders.overrides = [NSArray arrayWithObject:reminder];
newEvent.reminders.useDefault = [NSNumber numberWithBool:NO];
[self addEvent:newEvent];
}
- (void)addEvent:(GTLCalendarEvent *)event {
GTLQueryCalendar *query = [GTLQueryCalendar queryForEventsInsertWithObject:event
calendarId:@"primary"];
[self.service executeQuery:query
delegate:self
didFinishSelector:@selector(displayAddEventResultWithTicket:finishedWithObject:error:)];
}
- (void)displayAddEventResultWithTicket:(GTLServiceTicket *)ticket
finishedWithObject:(GTLCalendarEvents *)events
error:(NSError *)error {
if (error == nil) {
NSLog(@"I think event has been added successfully!");
} else {
NSLog(@"ERROR : %@", error.localizedDescription);
}
}
But I am getting the error in response "The operation couldn’t be completed. (Insufficient Permission)"
Thanks,