0

我正在创建一个从谷歌日历中提取事件的在线议程,它目前正在提取重复事件的第一个实例的开始日期。我可以用 api 和 javascript 做些什么来显示每个事件的实际日期,而不仅仅是第一个实例?

我的 HTML:

<div ng-controller="calCtrl">
<div ng-repeat="event in events">
  <div class="event-row">
    <span id="eventTitle">{{ event.summary }}</span>
    <span id="eventDate">{{ event.start.date | date:'EEE M/d/yyyy' }}{{ event.start.dateTime | date:'EEE M/d/yyyy' }}</span> // 
    <span id="eventTime">{{event.start.dateTime | date:'H:mm' }}</span>
    <span id="eventLocation">{{event.location}}</span>
  </div>
</div>

到目前为止,我的 JS:

var app = angular.module('eventApp', []);

app.factory('calendarServ', ['$http', function($http) {
  var today = (new Date()).toISOString();
  var APIKey = "___________";
  var url = "https://www.googleapis.com/calendar/v3/calendars/–––––––/events?maxResults=30&&timeMin=" + today + "&key=" + APIKey;

  return $http.get(url)
    .success(function(data) {
      return data;
    })
    .error(function(err) {
      return err;
    });
}]);

app.controller('calCtrl', ["$scope", "$http", "calendarServ", function($scope, $http, calendarServ) {
  $scope.events;

  calendarServ.success(function(data) {
    $scope.events = data.items;
  });
}]);
4

1 回答 1

0

instances您可以通过向以下 API 端点发出请求来获取重复事件的实际数据:

https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events/{eventId}/instances

您将获得一个包含重复事件实例的对象,以及它们的详细信息,例如开始时间、结束时间等。

示例响应:

{
      "status": "confirmed", 
      "kind": "calendar#event", 
      "end": {
        "timeZone": "Europe/Madrid", 
        "dateTime": "2020-04-07T12:30:00+02:00"
      }, 
      "created": "2020-03-24T10:24:37.000Z", 
      "iCalUID": "xxxxxxxxxxxxxxxxxx", 
      "reminders": {
        "useDefault": true
      }, 
      "htmlLink": "https://www.google.com/calendar/event?eid=-x-x-x-x-x-x-x-x-x-x-x-x--x-x-x", 
      "sequence": 0, 
      "updated": "2020-03-24T10:24:37.166Z", 
      "summary": "Test recurring event", 
      "start": {
        "timeZone": "Europe/Madrid", 
        "dateTime": "2020-04-07T11:30:00+02:00"
      }, 
      "etag": "\"3170xxxxdddd2000\"", 
      "originalStartTime": {
        "timeZone": "Europe/Madrid", 
        "dateTime": "2020-04-07T11:30:00+02:00"
      }, 
      "recurringEventId": "50qkopajasmentalescsql", 
      "organizer": {
        "self": true, 
        "email": "fatt.miks@egfreeed.eu"
      }, 
      "creator": {
        "self": true, 
        "email": "fatt.miks@egfreeed.e"
      }, 
      "id": "50qkoeauc7jpn3nmelih5loitmustB&wor00Z"
    }

注意: 查看OAuthPlayground以测试 Google API。

参考: - 日历 API事件实例

于 2020-03-24T10:43:24.607 回答