在谷歌日历API的events.list的响应中查找日历所有者的电子邮件

Finding email of calendar owner in the response of google calendar API's events.list?

本文关键字:日历 查找 所有者 电子邮件 响应 events 谷歌 API list      更新时间:2023-09-26

我正在开发一个显示同事日历统计信息的网络应用程序。为了显示此人的电子邮件,我使用了一个名为"摘要"的字段(基本上响应对象不包含id字段。它只有summary字段。

在大多数情况下,它是该人的电子邮件。它有效。

但是,如果该人将日历的名称更改为"工作"或其他名称,则显示为"工作"而不是"cathie@mydomain.com"。在这种情况下,我无法知道他/她的电子邮件,因此我无法打印这些统计数据。

问题

  1. gapi.client.calendar.events.list响应的 API 响应中是否有包含日历所有者电子邮件的字段?

  2. 是否有任何javascript技巧可以将此信息(calendarId)传递到'request.execute(function(resp)'并从回调函数内部访问它?

  3. 如果有标准的方法,请提出建议。


function getStatistics() {
    people = ['Alice', 'Bob', 'Cathie'];
    people.forEach(fetchStats);
}
function fetchStats(person) {
    var calendarId = person + '@mydomain.com';
    // ... some code
    var request = gapi.client.calendar.events.list({
        'calendarId': calendarId,
        'timeMax': (new Date()).toISOString(),
        'timeMin': '2016-01-01T00:00:00+05:30'
  });
  request.execute(function(resp) {
        var calendarId = resp.summary;
        if (calendarId.indexOf('@') == -1) {
            window.alert(resp + "'n" + calendarId);
            return;
        }
        // code to render statistics on events of the calendarId
  );
}
function getStatistics() {
    people = ['Alice', 'Bob', 'Cathie'];
    people.forEach(fetchStats);
}
function fetchStats(person) {
    var calendarId = person + '@mydomain.com';
    // ... some code
    var request = gapi.client.calendar.events.list({
        'calendarId': calendarId,
        'timeMax': (new Date()).toISOString(),
        'timeMin': '2016-01-01T00:00:00+05:30'
    });
  request.execute(function(resp) {
        //use the calendarId variable set above
        if (calendarId.indexOf('@') == -1) {
            window.alert(resp + "'n" + calendarId);
            return;
        }
        // code to render statistics on events of the calendarId
      });
}

您所要做的就是在回调中删除 calendarId 的本地设置。 回调仍然可以在您的 fetchStats 函数范围内引用,我刚刚对其进行了测试,它似乎工作正常。