5

こんにちは、私の主な目標は、Google カレンダーからすべてのイベントを取得し、その下に日付 (および可能な場合は時間) を付けて名前を表示することです。javascript google calendar api v3 を使用していますが、各イベントの日付を取得する際に問題が発生しています。問題をさらに説明する前に、現在のコードを次に示します。

var clientId = '200816328603.apps.googleusercontent.com';
var apiKey = 'AIzaSyD3rbV__d8u6r9u5GioBU0oVwa-53YXRqM';
var scopes = 'https://www.googleapis.com/auth/calendar';

function handleClientLoad() {
  gapi.client.setApiKey(apiKey);
  window.setTimeout(checkAuth,1);
  checkAuth();
}

function checkAuth() {
  gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
      handleAuthResult);
}

function handleAuthResult(authResult) {
  var authorizeButton = document.getElementById('authorize-button');
  if (authResult) {
    authorizeButton.style.visibility = 'hidden';
    makeApiCall();
  } else {
    authorizeButton.style.visibility = '';
    authorizeButton.onclick = handleAuthClick;
   }
}

function handleAuthClick(event) {
  gapi.auth.authorize(
      {client_id: clientId, scope: scopes, immediate: false},
      handleAuthResult);
  return false;
}

//document.createTextNode(resp.items[i].summary)

function makeApiCall() {

  gapi.client.load('calendar', 'v3', function() {
    var request = gapi.client.calendar.events.list({
      'calendarId': 'pvhs.k12.nj.us_r6jaor04o80hpsaldf17civeio@group.calendar.google.com'
    });

    request.execute(function(resp) {
      for (var i = 0; i < resp.items.length; i++) {

        //---------nodes for html elements
        var title = document.createTextNode(resp.items[i].summary); //titles are undefined so I'm using the summary as title instead
        //var description = document.createTextNode(resp.items[i].description); //there are no descriptions apparently
        var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date); //resp.items[i].date returns undefined

        //---------html elements
        var div = document.createElement('div');
        div.className = resp.items[i].summary;

        var h1 = document.createElement('h1');
        h1.appendChild(title);
        div.appendChild(h1);

        //loop is to filter out all the undefined
        if (date.textContent != 'Start: undefined End: undefined') {
          var p = document.createElement('p');
          p.appendChild(date);
          div.appendChild(p);
        }

        document.body.appendChild(div);
      }
    });
  });
}

現在 resp.items[i].start.date と resp.items[i].end.date は時々日付を返しますが、時々 undefined を返すだけです。では、他にどのようにイベントの日付を取得できますか?

これを回避するための私のアイデアは、月の毎日をループして、その日のすべてのイベントを取得することでした。ただし、必要な日の RFC3339 タイムスタンプを使用して timeMax および timeMin パラメータを追加しようとすると、何も返されませんでした。誰かがこれを達成するための例を教えてもらえますか?

どんな助けでも大歓迎です。

4

1 に答える 1

8

timeMin または timeMax を使用するには、'singleEvents' を true に設定する必要があります。これにより、イベント グループではなく、繰り返し発生するイベントの個々のインスタンスが返されると思います。

var request = gapi.client.calendar.events.list({
        'calendarId': 'pvhs.k12.nj.us_r6jaor04o80hpsaldf17civeio@group.calendar.google.com',
        'singleEvents': true, /* required to use timeMin */ 
        'timeMin': '2013-02-01T11:43:22.000Z'
    });

それが役立つことを願っています。

于 2013-05-15T13:29:22.167 に答える