简体   繁体   English

Google Calendar API v3 JavaScript格式

[英]Google calendar API v3 javascript format

I'm utilizing the new Google calendar API to create a list of events on a website, and I'm having trouble formatting the output. 我正在使用新的Google Calendar API在网站上创建事件列表,但在格式化输出时遇到了麻烦。 I followed the tutorial at this link: https://developers.google.com/google-apps/calendar/quickstart/js 我通过以下链接关注了本教程: https : //developers.google.com/google-apps/calendar/quickstart/js

By following the tutorial I was able to get everything up and running quickly. 通过学习本教程,我可以快速启动并运行所有内容。 I wanted to style the list of events for my website but I'm not sure how to format the output. 我想为我的网站设置事件列表的样式,但不确定如何格式化输出。 In the tutorial I followed I used OAuth to give me a client ID instead of an API key. 在本教程中,我遵循了使用OAuth为我提供客户端ID而不是API密钥的方法。 Right now in this tutorial the output of events is a solid block of text thats generated with createTextNode() . 现在,在本教程中,事件的输出是由createTextNode()生成的纯文本块。

Here is a portion from the tutorial above that prints the calendar events to the website: 这是上面教程的一部分,将日历事件打印到网站上:

     /**
   * 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 request = gapi.client.calendar.events.list({
      'calendarId': 'primary',
      'timeMin': (new Date()).toISOString(),
      'showDeleted': false,
      'singleEvents': true,
      'maxResults': 10,
      'orderBy': 'startTime'
    });

    request.execute(function(resp) {
      var events = resp.items;
      appendPre('Upcoming events:');

      if (events.length > 0) {
        for (i = 0; i < events.length; i++) {
          var event = events[i];
          var when = event.start.dateTime;
          if (!when) {
            when = event.start.date;
          }
          appendPre(event.summary + ' (' + when + ')')
        }
      } else {
        appendPre('No upcoming events found.');
      }

    });
  }

  /**
   * Append a pre element to the body containing the given message
   * as its text node.
   *
   * @param {string} message Text to be placed in pre element.
   */
  function appendPre(message) {
    var pre = document.getElementById('output');
    var textContent = document.createTextNode(message + '\n');
    pre.appendChild(textContent);
  }

And the result is a list of events with the title of the event and the date in the ISO format. 结果是事件列表,其中包含事件的标题和日期(ISO格式)。

QUESTION: How can you format this information so that the title of each event will be in a h1 tag and the date/time will be in a h2 tag instead of all of the output in one giant text node? 问题:如何设置此信息的格式,以使每个事件的标题都位于h1标签中,而日期/时间位于h2标签中,而不是所有输出均位于一个巨型文本节点中?

Also, I'm using a private calendar. 另外,我正在使用私人日历。

EDIT: I found this repo https://github.com/MilanKacurak/FormatGoogleCalendar This looks exactly like the kind of formatting I'm looking for, but it only works for public calendars. 编辑:我发现了这个仓库https://github.com/MilanKacurak/FormatGoogleCalendar这看起来与我正在寻找的格式完全一样,但它仅适用于公共日历。 Does anyone know if there is a way utilize something like this with a private calendar? 有谁知道是否可以通过私人日历使用这种方法?

With a little more digging I was able to find a similar question and was able to use it to solve my problem. 经过更多的挖掘,我能够找到一个类似的问题,并能够使用它来解决我的问题。

In this link, the answer to this question helped solve my question. 在此链接中,该问题的答案有助于解决我的问题。

Retrieve Google Calendar events using API v3 in javascript 在JavaScript中使用API​​ v3检索Google日历事件

In this link it says it is for public calendars, but I was able to use it with my private calendar as well. 在此链接中,它说它是用于公共日历的,但我也可以将其与我的私人日历一起使用。 I guess the biggest problem I was having was figuring out how to format the response from the api to include custom css class names and styles. 我想我遇到的最大问题是弄清楚如何格式化api的响应以包含自定义CSS类名称和样式。 If you know of a different/better answer please let me know. 如果您知道其他/更好的答案,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Google Calendar API v2到V3-Javascript - From Google Calendar API v2 to V3 - Javascript 在javascript中使用API​​ v3检索Google日历事件 - Retrieve Google Calendar events using API v3 in javascript 使用带有JavaScript的Google Calendar api v3在Google Calendar中创建记录事件(jquery ajax POST) - Creating reccuring events in Google Calendar using Google Calendar api v3 with javascript (jquery ajax POST) Google Calendar API v3 sendNotification参数 - Google Calendar API v3 sendNotification param 谷歌日历api v3 calendar.events.list并在javascript中使用timeMax,timeMin - google calendar api v3 calendar.events.list and using timeMax,timeMin in javascript 如何使用 Google Calendar API v3 (JavaScript) 删除事件通知 - How to remove event notification using Google Calendar API v3 (JavaScript) 无法在JavaScript的Google Calendar(v3)API中使用OAuth 2.0进行身份验证 - Cannot Authenticate using OAuth 2.0 in Google Calendar (v3) API in JavaScript 使用JavaScript Google Calendar API V3获取特定日期的事件 - Get events from a certain day with the javascript google calendar api v3 使用Javascript和Google Calendar API v3,如何允许用户指定非主日历来添加事件? - Using Javascript & Google Calendar API v3, how do I allow the user to specify a non-primary calendar to add an event? Google Maps Javascript API V3无法正常工作 - Google Maps Javascript API V3 not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM