gpt4 book ai didi

ios - 从 iOS 将事件添加到谷歌日历

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:59:19 24 4
gpt4 key购买 nike

我按照以下教程从谷歌日历中获取事件,效果很好。 https://developers.google.com/google-apps/calendar/quickstart/ios

现在我卡在了我的 iOS 应用程序的插入事件中,因此它也可以与 Web 同步。请指导我正确的方向或发布一些示例代码。

我在 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];

授权似乎很好,因为获取事件工作得很好。但我正在使用以下代码添加事件

- (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);
}
}

但我收到错误响应“操作无法完成。(权限不足)”

谢谢,

最佳答案

要将事件添加到日历,请使用以下方法

[GTLQueryCalendar queryForEventsInsertWithObject:yourEventObject calendarId:yourCalendarId]

另请注意,您必须授权范围为 kGTLAuthScopeCalendar 才能拥有读/写访问权限。

关于ios - 从 iOS 将事件添加到谷歌日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31176308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com