2016-08-24 60 views
1

我想从Google Calendar API for iOS应用程序中获取生日。现在我可以从Google日历中获取事件。适用于iOS的Google Calendar API返回BirthDays?

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

如何从Google Calendar API for iOS获取生日。 我必须去通过这个文档,谷歌日历API: https://developers.google.com/google-apps/calendar/quickstart/ios

+0

可以帮助我在谷歌日历迅速 –

回答

0

我已经在这工作之前,这是我发现了什么。尽管默认情况下,生日活动没有有效的'eventIDs',看起来像2016_BIRTHDAY_self(今年),所以当您使用Events: list获取它时,不会返回任何内容。你必须先将其添加:

在你的谷歌日历:

  1. 单击默认birthday icon在您的日历。
  2. 点击“复制到我的日历”。
  3. 这将打开事件UI。您可以在说明中添加更多详细信息。然后保存。

现在,重复的生日事件会添加到您的日历中,但是这次它有一个有效的eventID。因此,当您使用Events:列表进行另一个呼叫时,它会发送returns the event

如何在iOS中做到这一点?

URI请求:

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

您可以use NSURLConnection

// 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]; 

获取生日人们使用API​​:

1.设置勾选你的生日公众在Google+中Basic Information“显示出生年份'

  • 。利用人API URI请求的:

    GET https://www.googleapis.com/plus/v1/people/userId

  • 使用Try-it到现在与参数测试:

    userId -> me 
    fields -> birthday 
    Authorize and Execute. 
    
    +0

    因此,如果没有创建活动,谷歌日历API不会给生日? @noogui –

    +0

    是的,这就是我找到的。 – noogui

    +0

    @MdBajlurRashid你似乎不同意? – noogui

    0

    它是可能从谷歌日历得到的所有生日没有复制到您的日历

    获取生日日历 id从谷歌。

    • 打开谷歌日历
    • 点击生日日历设置

    enter image description here

    • 你会从日历地址
    • 使用得到日历ID那用于获取事件

      You can also get Calendar id through Google API 
      https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list 
      

      对于iOS检查下面的代码

      ​​

      委托方法

      func displayResultWithTicket(
      ticket: GTLRServiceTicket, 
      finishedWithObject response : GTLRCalendar_Events, 
              error : NSError?) { 
      
      
          } 
      

      日历ID,它的工作对我来说

    感谢。

    +0

    可以帮助我与谷歌日历创建活动 –

    +0

    我只运行谷歌日历代码成功,它工作正常 –