我正试图通过Google Calendar API for iOS应用程序获得生日。现在,我可以从Google日历中获取活动。
- (void)fetchEvents {
GTLQueryCalendar *query = [GTLQueryCalendar queryForEventsListWithCalendarId:@"primary"];
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:)];}
- (void)displayResultWithTicket:(GTLServiceTicket *)ticket
finishedWithObject:(GTLCalendarEvents *)events
error:(NSError *)error {
if (error == nil) {
NSMutableString *eventString = [[NSMutableString alloc] init];
if (events.items.count > 0) {
for (GTLCalendarEvent *event in events) {
GTLDateTime *start = event.start.dateTime ?: event.start.date;
NSString *startString =
[NSDateFormatter localizedStringFromDate:[start date]
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterShortStyle];
[eventString appendFormat:@"\n %@\n %@\n\n%@\n", event.summary, startString, event.descriptionProperty];
}
} else {
[eventString appendString:@"No upcoming events found."];
}
NSLog(@"eventString %@",eventString);
} else {
[self showAlert:@"Error" message:error.localizedDescription];
}
}
如何从适用于iOS的Google Calendar API获取生日。 我已阅读Google Calendar API的此文档: 的 https://developers.google.com/google-apps/calendar/quickstart/ios
答案 0 :(得分:0)
我之前已经研究过这个,这就是我发现的。虽然默认情况下存在,但生日事件没有有效的“eventID”,看起来像2016_BIRTHDAY_self(今年),因此当您使用Events: list获取它时,不会返回任何内容。你必须先添加它:
在您的Google日历上:
现在,重复的生日事件会添加到您的日历中,但这一次,它有一个有效的eventID。因此,当您使用Events:list进行另一个调用时,它returns the event。
如何在iOS中执行此操作?
URI请求:
GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events
// Create the request.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]];
// Create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
使用People API获取生日:
1.通过勾选“出生年份”
,在Google+ Basic Information中将您的生日设置为公开使用People API URI请求:
使用Try-it现在使用参数进行测试:
userId -> me
fields -> birthday
Authorize and Execute.
答案 1 :(得分:0)
可能将所有生日从谷歌日历无需复制带到您的日历
获取生日日历 ID来自谷歌。
使用该日历ID获取活动
You can also get Calendar id through Google API
https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list
对于iOS,请检查以下代码
let query = GTLRCalendarQuery_EventsList.queryWithCalendarId("calendar id")
service.executeQuery(
query,
delegate: self,
didFinishSelector: #selector(displayResultWithTicket(_: finishedWithObject:error:)))
委托方法
func displayResultWithTicket(
ticket: GTLRServiceTicket,
finishedWithObject response : GTLRCalendar_Events,
error : NSError?) {
}
它为我工作
感谢。