使用Javascript在Google日历中插入事件

时间:2016-04-22 01:06:54

标签: javascript google-calendar-api

我的客户端ID正确但在此示例中隐藏。

我需要帮助将活动发布到我的日历。我相信我的代码是正确的,但我需要别人的眼睛。

我只需要将活动发布到日历上。

SCOPES = ["https://www.googleapis.com/auth/calendar"]
function checkAuth() {
    gapi.auth.authorize(
      {
        'client_id': CLIENT_ID,
        'scope': SCOPES.join(' '),
        'immediate': true
      }, handleAuthResult);
  }

  /**
   * Handle response from authorization server.
   *
   * @param {Object} authResult Authorization result.
   */
  function handleAuthResult(authResult) {
    var authorizeDiv = document.getElementById('authorize-div');
    if (authResult && !authResult.error) {
      // Hide auth UI, then load client library.
      authorizeDiv.style.display = 'none';
      loadCalendarApi();
    } else {
      // Show auth UI, allowing the user to initiate authorization by
      // clicking authorize button.
      authorizeDiv.style.display = 'inline';
    }
  }

  /**
   * Initiate auth flow in response to user clicking authorize button.
   *
   * @param {Event} event Button click event.
   */
  function handleAuthClick(event) {
    gapi.auth.authorize(
      {client_id: CLIENT_ID, scope: SCOPES, immediate: false},
      handleAuthResult);
    return false;
  }

  /**
   * Load Google Calendar client library. List upcoming events
   * once client library is loaded.
   */
  function loadCalendarApi() {
    gapi.client.load('calendar', 'v3', listUpcomingEvents);
  }

  /**
   * Print the summary and start datetime/date of the next ten events in
   * the authorized user's calendar. If no events are found an
   * appropriate message is printed.
   */
  function listUpcomingEvents() {
    var event = {
"summary":"Here"
"description":"Now"
"start":
{
"dateTime":"2016-04-21T12:00:00.000-07:00"
"timeZone":"America/Los_Angeles"
}
"end":
{
"dateTime":"2016-04-21T12:30:00.000-07:00"
"timeZone":"America/Los_Angeles"
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});

request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
}); 
  }

0 个答案:

没有答案