菜鸟教程小白 发表于 2022-12-11 17:21:21

ios - 适用于 iOS 的 Google Calendar API 返回BirthDays?


                                            <p><p>我正在尝试从适用于 iOS 应用程序的 Google Calendar API 获取生日。现在我可以从 Google 日历中获取事件了。</p>

<pre><code>- (void)fetchEvents {
GTLQueryCalendar *query = ;
query.maxResults = 10;
query.timeMin =
                                     timeZone:];;
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 = [ init];
      if (events.items.count &gt; 0) {
            for (GTLCalendarEvent *event in events) {
                GTLDateTime *start = event.start.dateTime ?: event.start.date;
                NSString *startString =
               
                                             dateStyle:NSDateFormatterShortStyle
                                             timeStyle:NSDateFormatterShortStyle];
                ;

            }
      } else {
            ;
      }

      NSLog(@&#34;eventString %@&#34;,eventString);

    } else {
      ;
    }
}
</code></pre>

<p>如何从适用于 iOS 的 Google Calendar API 获取生日。
我已经阅读了 Google Calendar API 的文档:
<strong> <a href="https://developers.google.com/google-apps/calendar/quickstart/ios" rel="noreferrer noopener nofollow">https://developers.google.com/google-apps/calendar/quickstart/ios</a> </strong></p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我以前做过这方面的工作,这就是我发现的。虽然默认情况下存在,但生日事件没有有效的“eventID”,看起来像 2016_BIRTHDAY_self(今年),所以当你使用 <a href="https://developers.google.com/google-apps/calendar/v3/reference/events/list" rel="noreferrer noopener nofollow">Events: list</a> 获取它时,不返回任何内容。您必须先添加它:</p>

<p>在您的 Google 日历上:</p>

<ol>
<li>点击默认<a href="http://imgur.com/GjPiqSA" rel="noreferrer noopener nofollow">birthday icon</a>在您的日历中。</li>
<li>点击“复制到我的日历”。</li>
<li>这将打开事件 UI。您可以在说明中添加其他详细信息。然后保存。</li>
</ol>

<p>现在,一个重复的生日事件已添加到您的日历中,但这次它有一个有效的 eventID。因此,当您使用 Events:list 调用另一个电话时,它会 <a href="http://imgur.com/5L05qfm" rel="noreferrer noopener nofollow">returns the event</a> .</p>

<p>如何在 iOS 中做到这一点?</p>

<p>URI 请求:</p>

<pre><code>GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events
</code></pre>

<p>您可以<a href="http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/" rel="noreferrer noopener nofollow">use NSURLConnection</a> :</p>

<pre><code>// Create the request.
NSURLRequest *request = ];

// Create url connection and fire request
NSURLConnection *conn = [ initWithRequest:request delegate:self];
</code></pre>

<p><strong>使用 People API 获得生日:</strong></p>

<p>1.在 Google+ 中将您的生日设为公开 <a href="https://support.google.com/plus/answer/1350405?hl=en" rel="noreferrer noopener nofollow">Basic Information</a>通过勾选“显示出生年份”</p>

<ol 开始=“2”>
<li><p>利用 People API URI 请求:</p>

<p>获取 <a href="https://www.googleapis.com/plus/v1/people/userId" rel="noreferrer noopener nofollow">https://www.googleapis.com/plus/v1/people/userId</a> </p></li>
</ol>

<p>使用 <a href="https://developers.google.com/+/web/api/rest/latest/people/get#try-it" rel="noreferrer noopener nofollow">Try-it</a>现在用参数测试它:</p>

<pre><code>userId -&gt; me
fields -&gt; birthday
Authorize and Execute.
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 适用于 iOS 的 Google Calendar API 返回BirthDays?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39132020/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39132020/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 适用于 iOS 的 Google Calendar API 返回BirthDays?