如何使用带有Objective-C的Google日历列表插入。
https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert#response
我要添加公开日历[ID:b3b9bke782agahkklrqujdhi74@group.calendar.google.com] 到我的日历,但有一些错误
Error Domain=com.google.GTLJSONRPCErrorDomain Code=**403** "(Insufficient Permission)" UserInfo={error=Insufficient Permission, NSLocalizedFailureReason=(Insufficient Permission), GTLStructuredError=GTLErrorObject 0x7f9b40d0da00: {message:"Insufficient Permission" data:[1] code:403}}
2016-03-10 17:34:23.022 calendar20160225[10337:413037] error:(null)
我从https://developers.google.com/google-apps/calendar/quickstart/ios
进行编辑我添加此内容并收到错误
-(void)myCalendarQuery
{
NSString* enter code herenewCalendarName=@"b3b9bke782agahkklrqujdhi74@group.calendar.google.com";
GTLCalendarCalendarListEntry *entry=[GTLCalendarCalendar object];
GTLServiceCalendar *service = self.service;
GTLCalendarCalendar *newEntry = [GTLCalendarCalendar object];
newEntry.summary = newCalendarName;
newEntry.timeZone = [[NSTimeZone localTimeZone] name];
GTLQueryCalendar *query = [GTLQueryCalendar queryForCalendarsInsertWithObject:newEntry];
GTLServiceTicket* editCalendarListTicket =[[GTLServiceTicket alloc]init];
[self.service executeQuery:query
delegate:self
didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
editCalendarListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
// Callback
//editCalendarListTicket = nil;
if (error == nil) {
[self fetchCalendarList];
} else {
NSLog(@"error:%@",error);
[self fetchCalendarList];
[self showAlert:@"Add failed" message:[NSString stringWithFormat:@"Calendar add failed: %@", error]];
}
}];
//b3b9bke782agahkklrqujdhi74@group.calendar.google.com
GTLQueryCalendar *query2 = [GTLQueryCalendar queryForEventsListWithCalendarId:@"b3b9bke782agahkklrqujdhi74@group.calendar.google.com"];
[GTLQueryCalendar queryForEventsInsertWithObject:query calendarId:@"b3b9bke782agahkklrqujdhi74@group.calendar.google.com"];
query.maxResults = 10;
query.timeMin = [GTLDateTime dateTimeWithDate:[NSDate date]
timeZone:[NSTimeZone localTimeZone]];;
query.singleEvents = YES;
query.orderBy = kGTLCalendarOrderByStartTime;
[self.service executeQuery:query
delegate:self
didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
// [GTLQueryCalendar queryForAclInsertWithObject:query calendarId:@"b3b9bke782agahkklrqujdhi74@group.calendar.google.com"];
}
答案 0 :(得分:0)
这很有效。
-(void)getCalendar
{
NSString* newCalendarName = @"b3b9bke782agahkklrqujdhi74@group.calendar.google.com";
GTLQueryCalendar *query2 = [GTLQueryCalendar queryForCalendarsGetWithCalendarId:newCalendarName];
[self.service executeQuery:query2
delegate:self
didFinishSelector:@selector(displayResultWithTicket2:finishedWithObject:error:)];
}
但是,如果我想在我的日历中添加一些东西。它将无法工作。我可能的问题是我需要范围kGTLAuthScopeCalendar具有读/写访问权限。 (我只是从Add event to google calendar from ios找到。另请注意,您必须使用范围kGTLAuthScopeCalendar的答案授权才能具有读/写访问权限。)
答案 1 :(得分:0)
我解决了这个问题。我的范围只有calendarRealOnly。 我最后添加了https://www.googleapis.com/auth/calendar。
[self.googleOAuth authorizeUserWithClienID:@"clienID"
andClientSecret:@"clentSecret"
andParentView:self.view
andScopes:[NSArray arrayWithObjects:
@"https://www.googleapis.com/auth/userinfo.profile",
@"https://www.googleapis.com/auth/calendar",
@"https://www.googleapis.com/auth/calendar.readonly",
nil]
];
GTLCalendarCalendarListEntry*calendarListEntry=[GTLCalendarCalendarListEntry object];
calendarListEntry.identifier = @"b3b9bke782agahkklrqujdhi74@group.calendar.google.com";
GTLQueryCalendar *queryInsertCalendarList = [GTLQueryCalendar queryForCalendarListInsertWithObject:calendarListEntry];
[self.service executeQuery:queryInsertCalendarList
delegate:self
didFinishSelector:nil];