如何创建链接以将条目添加到日历?

发布于 2024-11-04 18:24:48 字数 385 浏览 0 评论 0 原文

我在这家夜总会工作,目前正在为他们制作一个网站,他们有很多活动,他们的网站很多都是围绕活动构建的,今天他们为每个活动制作了一个 Facebook 活动,但如果有一个“添加到我的日历”按钮,将其添加到您的 iCal 或 Google 日历(甚至可能是 Outlook)。

我已经设法弄清楚如何制作日历提要,但随后它将作为新日历添加,唯一的好处是人们可以“订阅事件”,但为每个事件都有一个日历是相当混乱的。所以我想知道如何实现一个功能,让他们可以轻松地将其添加到他们的主日历中。像 mailto: 链接一样思考,但如果可能的话,用于日历。

另外,当我谈论这个主题时,有谁知道是否可以自动将事件从 Facebook 导入到 WordPress 或将事件从 WordPress 导出到 Facebook,这会很棒,但这并不那么重要。

I'm working for this nightclub and are currently making a website for them, they've got lots events and their site is built a lot around events, today they make an facebook event of every event but it would be killer to have a "Add to my Calendar" button which added it to your iCal or Google Calendar (or maybe even Outlook).

I've managed to figure out how to make an calendar feed but then it will be added as a new calendar, only good thing is that people can "subscribe to events" but it's quite messy to have an calendar for every event. So I would like to know how to implement a function which lets them add it to their main calendar easily. Think like a mailto: link but for calendars if that's possible.

Also while I'm on the subject, does anyone know if it's possible to automatically import an event from Facebook to WordPress or export an event from WordPress to Facebook that would be great, but that's not so important.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

迷乱花海 2024-11-11 18:24:48

戴夫帖子中的链接很棒。只是将有关谷歌链接的一些技术细节放入此处的答案中:

Google Calendar Link

添加到 gCal

参数为:

  • action=TEMPLATE(必需)
  • 文本(事件的 url 编码名称)
  • 日期(ISO 日期格式,开始日期/结束日期 - 必须同时具有开始和结束时间 - 按钮生成器将让您留下结束时间空白,但你必须有一个,否则它将不起作用。)
    • 使用用户的时区:20131208T160000/20131208T180000
    • 要使用全球时间,请转换为 UTC,然后使用 20131208T160000Z/20131208T180000Z
    • 全天活动,您可以使用20131208/20131209 - 请注意,按钮生成器会出错。您必须使用以下日期作为全天活动的结束日期,或者将您想要的结束日期加 1 天。
  • 详细信息(url 编码的事件描述/详细信息)
  • 位置(url 编码的事件位置 - 确保它是谷歌地图可以轻松读取的地址)

2018 年 2 月更新:

这是一个新的链接结构,似乎支持新的谷歌版本的谷歌日历 w /o 需要 API 交互:

https://calendar.google.com/calendar/r/eventedit?text=My+Custom+Event&dates=20180512T230000Z/20180513T030000Z&details=For+details,+link+此处: +https://example.com/tickets-43251101208&location=Garage+Boston+-+20+Linden+Street+-+Allston,+MA+02134

新基本网址:https://calendar. google.com/calendar/r/eventedit

新参数:

  • 文本(活动名称)
  • 日期(ISO 日期格式,开始日期/结束日期 - 必须同时包含开始时间和结束时间)
    • 具有开始/结束时间的活动:20131208T160000/20131208T180000
    • 全天活动,您可以使用20131208/20131209 - 结束日期必须比您希望的结束日期早+1 天
  • ctz(时区,例如 America/New_York - 留空以使用用户的默认时区。强烈建议几乎在所有情况下都包含此内容,例如,视频会议的提醒:如果不同时区的三个人单击此链接并为他们“自己的”星期二上午 10:00 设置提醒,则效果不会很好。)
  • 详细信息(url 编码的活动描述/详细信息)
  • location (url 编码的活动位置 - 确保它是 google 地图可以轻松读取的地址)
  • add (逗号分隔的电子邮件列表 - 将客人添加到您的新活动)

注意:

  • 上面的旧 url 结构现在重定向到这里
  • 支持
  • 带时区的 https 交易,
  • 除了 %20 之外,更好地接受 + 空间(urlencoderawurlencode > 在 php 中 - 两者都有效)

The links in Dave's post are great. Just to put a few technical details about the google links into an answer here on SO:

Google Calendar Link

<a href="http://www.google.com/calendar/event?action=TEMPLATE&text=Example%20Event&dates=20131124T010000Z/20131124T020000Z&details=Event%20Details%20Here&location=123%20Main%20St%2C%20Example%2C%20NY">Add to gCal</a>

the parameters being:

  • action=TEMPLATE (required)
  • text (url encoded name of the event)
  • dates (ISO date format, startdate/enddate - must have both start and end time - the button generator will let you leave the endtime blank, but you must have one or it won't work.)
    • to use the user's timezone: 20131208T160000/20131208T180000
    • to use global time, convert to UTC, then use 20131208T160000Z/20131208T180000Z
    • all day events, you can use 20131208/20131209 - note that the button generator gets it wrong. You must use the following date as the end date for a one day all day event, or +1 day to whatever you want the end date to be.
  • details (url encoded event description/details)
  • location (url encoded location of the event - make sure it's an address google maps can read easily)

Update Feb 2018:

Here's a new link structure that seems to support the new google version of google calendar w/o requiring API interaction:

https://calendar.google.com/calendar/r/eventedit?text=My+Custom+Event&dates=20180512T230000Z/20180513T030000Z&details=For+details,+link+here:+https://example.com/tickets-43251101208&location=Garage+Boston+-+20+Linden+Street+-+Allston,+MA+02134

New base url: https://calendar.google.com/calendar/r/eventedit

New parameters:

  • text (name of the event)
  • dates (ISO date format, startdate/enddate - must have both start and end time)
    • an event w/ start/end times: 20131208T160000/20131208T180000
    • all day events, you can use 20131208/20131209 - end date must be +1 day to whatever you want the end date to be.
  • ctz (timezone such as America/New_York - leave blank to use the user's default timezone. Highly recommended to include this in almost all situations. For example, a reminder for a video conference: if three people in different timezones clicked this link and set a reminder for their "own" Tuesday at 10:00am, this would not work out well.)
  • details (url encoded event description/details)
  • location (url encoded location of the event - make sure it's an address google maps can read easily)
  • add (comma separated list of emails - adds guests to your new event)

Notes:

  • the old url structure above now redirects here
  • supports https
  • deals w/ timezones better
  • accepts + for space in addition to %20 (urlencode vs rawurlencode in php - both work)
荭秂 2024-11-11 18:24:48

更新(免费供个人使用):
现在支持 HTTPS

虽然我在下面的回答详细介绍了每个服务的操作方法,但在我看来,现在使用像 这样的第三方会更容易AddThisEvent [https://addthisevent.com]。它可以让您自定义许多选项以及添加到 Facebook 等。 不幸的是,他们现在已将其作为除个人使用之外的任何其他服务的付费服务,并且确实强制执行这一点。

我认为还有其他类似的第三方解决方案,但我只能谈论这个,到目前为止,它对我们来说效果很好。


对于“添加到我的 Google 日历”,他们曾经有一个可供您使用的代码生成器表单,但后来已将其删除。有关 Google 日历链接的更多详细信息,请参阅 squarecandy 的回答如下

对于 Outlook,情况要复杂一些,但基本上您需要使用事件数据创建一个 .vcs 文件,然后创建指向该文件的链接。 步骤-此处的分步说明

对于 iCal 链接,您可以使用 PHP 类 喜欢这个,或关注 本页说明,介绍如何创建 ics 文件(iCal 文件)。

UPDATE (free for personal use):
HTTPS IS NOW SUPPORTED

While my answer below detailing how-to for each service WILL work, IMO it's much easier now to go with a third-party like AddThisEvent [https://addthisevent.com]. It lets you customize lots of options as well as add to Facebook and more. Unfortunately, they've now made it a paid service for anything other than personal use and do enforce this.

I assume there are other third-party solutions like this one, but I can only speak to this one, and it has worked great for us so far.


For an "Add to my Google Calendar", they used to have a code generator form you could use, but have since taken it down. For more details on Google Calendar links, see squarecandy's answer below.

For Outlook, it's a BIT more complicated, but basically you need to create a .vcs file with the event's data, and just make a link to that file. Step-by-step instructions here.

For an iCal link, you could use a PHP class like this one, or follow this page's instructions on how to create an ics file (iCal file).

把回忆走一遍 2024-11-11 18:24:48

为了添加到 squarecandy 的 Google 日历贡献中,这里使用全新的

OUTLOOK CALENDAR 格式(无需创建 .ics)!

<a href="https://bay02.calendar.live.com/calendar/calendar.aspx?rru=addevent&dtstart=20151119T140000Z&dtend=20151119T160000Z&summary=Summary+of+the+event&location=Location+of+the+event&description=example+text.&allday=false&uid=">add to Outlook calendar</a>

测试一下

最好对摘要、位置和描述变量的值进行 url_encode。< /em>

为了了解知识,

YAHOO CALENDAR 格式

<a href="https://calendar.yahoo.com/?v=60&view=d&type=20&title=Summary+of+the+event&st=20151119T090000&et=20151119T110000&desc=example+text.%0A%0AThis+is+the+text+entered+in+the+event+description+field.&in_loc=Location+of+the+event&uid=">add to Yahoo calendar</a>

测试一下

在没有第三方的情况下进行测试有很多优点,例如在电子邮件中使用它。

To add to squarecandy's google calendar contribution, here the brand new

OUTLOOK CALENDAR format (Without a need to create .ics) !!

<a href="https://bay02.calendar.live.com/calendar/calendar.aspx?rru=addevent&dtstart=20151119T140000Z&dtend=20151119T160000Z&summary=Summary+of+the+event&location=Location+of+the+event&description=example+text.&allday=false&uid=">add to Outlook calendar</a>

test it

Best would be to url_encode the summary, location and description variable's values.

For the sake of knowledge,

YAHOO CALENDAR format

<a href="https://calendar.yahoo.com/?v=60&view=d&type=20&title=Summary+of+the+event&st=20151119T090000&et=20151119T110000&desc=example+text.%0A%0AThis+is+the+text+entered+in+the+event+description+field.&in_loc=Location+of+the+event&uid=">add to Yahoo calendar</a>

test it

Doing it without a third party holds a lot of advantages for example using it in emails.

一瞬间的火花 2024-11-11 18:24:48

Litmus 有一篇很棒的文章,详细介绍了如何构建一个在主要电子邮件和日历客户端上运行良好的简洁解决方案,包括为使用不同供应商的客户端的用户提供服务。

考虑到这个空间的非标准化性质,这绝非小事,但如果您愿意卷起袖子几天,您可以获得一些效果很好且不需要每月价格标签的东西以及使用限制!

https:// /www.litmus.com/blog/how-to-create-an-add-to-calendar-link-for-your-emails/

Litmus has a great post detailing how to build a neat solution that works well across the major email and calendar clients, including catering for users who use clients from different vendors.

It is far from trivial, given the non-standardised nature of this space, but if you're willing to roll up your sleeves for a couple of days, you can get something that works well and doesn't come with a monthly price tag and limits on usage!

https://www.litmus.com/blog/how-to-create-an-add-to-calendar-link-for-your-emails/

心如荒岛 2024-11-11 18:24:48

您可以生成一个 ics 文件,其中包含会议信息

ics 文件看起来像这样,

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.6.4//EN
METHOD:REQUEST
BEGIN:VEVENT
UID:c7a913c7-3276-4828-8606-b841f2870475
DTSTAMP:20220519T070000Z
SUMMARY: Booking you for this date
DESCRIPTION:You having been invited to the event 
DTSTART:20220519T070000Z
DURATION:PT1H
ORGANIZER;CN=Company Team:mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Not Amazing Attendee:mailto:*********@gmail.com
END:VEVENT
END:VCALENDAR

生成 ics 文件的 java 代码也在这里

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class iCal {

    private String version = "VERSION:1.0 \n";
    private String prodid = "PRODID://Elara/lofy/tanare/delp/314sum2015// \n";
    private String calBegin = "BEGIN:VCALENDAR \n";
    private String calEnd = "END:VCALENDAR \n";
    private String eventBegin = "BEGIN:VEVENT \n";
    private String eventEnd = "END:VEVENT \n";

    public void iCal() {
    }

    public static void main(String[] args) {

    }

    public void write(String name) {
        StringBuilder builder = new StringBuilder();
        builder.append(name);
        builder.append(".ics");

        String testExample = "UID:[email protected]\\nDTSTAMP:19970714T170000Z\\nORGANIZER;\n"
                + "    CN=John Doe:MAILTO:[email protected]\\nDTSTART:19970714T170000Z\n"
                + "    \\nDTEND:19970715T035959Z\\nSUMMARY:Bastille Day Party\\n";

        try {

            File file = new File(builder.toString());

            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(calBegin);
            bw.write(version);
            bw.write(prodid);
            bw.write(eventBegin);
            bw.write(testExample);
            bw.write(eventEnd);
            bw.write(calEnd);

            bw.close();

            System.out.println("Done");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} 

You can generate a ics file which include the meeting information

the ics file look like this

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.6.4//EN
METHOD:REQUEST
BEGIN:VEVENT
UID:c7a913c7-3276-4828-8606-b841f2870475
DTSTAMP:20220519T070000Z
SUMMARY: Booking you for this date
DESCRIPTION:You having been invited to the event 
DTSTART:20220519T070000Z
DURATION:PT1H
ORGANIZER;CN=Company Team:mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Not Amazing Attendee:mailto:*********@gmail.com
END:VEVENT
END:VCALENDAR

also the java code to generate ics file is here

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class iCal {

    private String version = "VERSION:1.0 \n";
    private String prodid = "PRODID://Elara/lofy/tanare/delp/314sum2015// \n";
    private String calBegin = "BEGIN:VCALENDAR \n";
    private String calEnd = "END:VCALENDAR \n";
    private String eventBegin = "BEGIN:VEVENT \n";
    private String eventEnd = "END:VEVENT \n";

    public void iCal() {
    }

    public static void main(String[] args) {

    }

    public void write(String name) {
        StringBuilder builder = new StringBuilder();
        builder.append(name);
        builder.append(".ics");

        String testExample = "UID:[email protected]\\nDTSTAMP:19970714T170000Z\\nORGANIZER;\n"
                + "    CN=John Doe:MAILTO:[email protected]\\nDTSTART:19970714T170000Z\n"
                + "    \\nDTEND:19970715T035959Z\\nSUMMARY:Bastille Day Party\\n";

        try {

            File file = new File(builder.toString());

            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(calBegin);
            bw.write(version);
            bw.write(prodid);
            bw.write(eventBegin);
            bw.write(testExample);
            bw.write(eventEnd);
            bw.write(calEnd);

            bw.close();

            System.out.println("Done");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} 
甜`诱少女 2024-11-11 18:24:48

简单&免费解决方案

使用add-to-calendar-button.com。
请参阅
现场演示

给定的代码将生成一个按钮,用于在日历中添加上午 8 点到 10 点的事件2024 年 4 月 9 日。

<script src="https://cdn.jsdelivr.net/npm/add-to-calendar-button@2" async defer></script>

<add-to-calendar-button id="calendarButton"
  name="Sample Event"
  description="Sample Description"
  startDate="2024-04-09"
  startTime="08:00"
  endTime="10:00"
  timeZone="Asia/Calcutta"
  location="India"
  options="'Apple','Google','iCal','Outlook.com','Yahoo','MicrosoftTeams','Microsoft365'"
></add-to-calendar-button>

此外,我还构建了一个 JS 函数来通过函数调用添加详细信息:

    function setCalendar() {
      const button = document.getElementById('calendarButton');
      if (button) {
        // Set event details
        button.setAttribute('name', 'Sample Event');
        button.setAttribute('description', 'Sample Description');
        button.setAttribute('startDate', '2024-04-09');
        button.setAttribute('startTime', '08:00');
        button.setAttribute('endTime', '10:00');
        button.setAttribute('timeZone', 'Asia/Calcutta');
        button.setAttribute('location', 'India');
        button.setAttribute('options', "'Apple','Google','iCal','Outlook.com','Yahoo','MicrosoftTeams','Microsoft365'");
      }
    }

    // Calling the function
    setCalendar();

如需更多自定义,请访问 此处

Simple & Free solution

Using CDN library provided by add-to-calendar-button.com.
See Live Demo

Given code will generate a button to add an event in calendar from 8 to 10am on 9th April 2024.

<script src="https://cdn.jsdelivr.net/npm/add-to-calendar-button@2" async defer></script>

<add-to-calendar-button id="calendarButton"
  name="Sample Event"
  description="Sample Description"
  startDate="2024-04-09"
  startTime="08:00"
  endTime="10:00"
  timeZone="Asia/Calcutta"
  location="India"
  options="'Apple','Google','iCal','Outlook.com','Yahoo','MicrosoftTeams','Microsoft365'"
></add-to-calendar-button>

Additionally, I have built a JS function to add the details through a function call:

    function setCalendar() {
      const button = document.getElementById('calendarButton');
      if (button) {
        // Set event details
        button.setAttribute('name', 'Sample Event');
        button.setAttribute('description', 'Sample Description');
        button.setAttribute('startDate', '2024-04-09');
        button.setAttribute('startTime', '08:00');
        button.setAttribute('endTime', '10:00');
        button.setAttribute('timeZone', 'Asia/Calcutta');
        button.setAttribute('location', 'India');
        button.setAttribute('options', "'Apple','Google','iCal','Outlook.com','Yahoo','MicrosoftTeams','Microsoft365'");
      }
    }

    // Calling the function
    setCalendar();

For more customizations, visit here.

春风十里 2024-11-11 18:24:48

您可以让程序创建日历的 .ics (iCal) 版本,然后您可以将此 .ics 导入到您想要的任何日历程序中:Google、Outlook 等。

我知道这篇文章很旧,所以我赢了不用费心输入任何代码。但如果您希望我提供如何执行此操作的概述,请对此发表评论。

You can have the program create an .ics (iCal) version of the calendar and then you can import this .ics into whichever calendar program you'd like: Google, Outlook, etc.

I know this post is quite old, so I won't bother inputting any code. But please comment on this if you'd like me to provide an outline of how to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文