简体   繁体   English

如何以编程方式将事件添加到 Outlook 日历或 Google 日历?

[英]How to add events to Outlook Calendar or Google Calendar programmatically?

I have a Java Web application from which the user can add events with date, subject and description (like tasks).我有一个 Java Web 应用程序,用户可以从中添加带有日期、主题和描述(如任务)的事件。 I want to send these events to the user's outlook calendar programmatically.我想以编程方式将这些事件发送到用户的 Outlook 日历。 Can anyone help me how to achieve this?谁能帮助我如何实现这一目标?

PS: If it can be done through Google Calendar tell me how to do that as I am not stuck with outlook :) PS:如果它可以通过谷歌日历完成,请告诉我如何做到这一点,因为我没有坚持使用 Outlook :)

You can now use Outlook Calendar REST API and send requests from your java code.您现在可以使用Outlook 日历 REST API并从您的 Java 代码发送请求。

For the auth flow see this getting started documentation .有关身份验证流程,请参阅此入门文档

Eg.例如。 POST to https://outlook.office.com/api/v2.0/me/calendars/{calendar_id}/events a JSON content like: POST 到https://outlook.office.com/api/v2.0/me/calendars/{calendar_id}/events一个 JSON 内容,如:

{
  "Subject": "Discuss the Calendar REST API",
  "Body": {
    "ContentType": "HTML",
    "Content": "I think it will meet our requirements!"
  },
  "Start": {
      "DateTime": "2014-02-02T18:00:00",
      "TimeZone": "Pacific Standard Time"
  },
  "End": {
      "DateTime": "2014-02-02T19:00:00",
      "TimeZone": "Pacific Standard Time"
  },
  "Attendees": [
    {
      "EmailAddress": {
        "Address": "janets@a830edad9050849NDA1.onmicrosoft.com",
        "Name": "Janet Schorr"
      },
      "Type": "Required"
    }
  ]
}

Google Calendar seems to be the best choice, as you can use the Google Calendar API . Google Calendar 似乎是最佳选择,因为您可以使用Google Calendar API For an example written in Java, look here .有关用 Java 编写的示例,请查看此处 Just make sure to note the GCal API usage limits .请务必注意GCal API 使用限制

Outlook doesn't seem to have some sort of an API, but maybe you can make use of or modify something like the Jpst or java-libpst . Outlook 似乎没有某种 API,但也许您可以使用或修改Jpstjava-libpst 之类的东西。

Albert already answered for Google.阿尔伯特已经为谷歌回答了。 For Outlook you use either OLE automation or Microsoft Graph .对于 Outlook,您可以使用OLE 自动化Microsoft Graph * *

Note that the second option is only for Outlook accounts talking to Exchange Server.请注意,第二个选项仅适用于与 Exchange Server 通信的 Outlook 帐户。 If you access other mail backends through Outlook you can't use Graph, only use OLE.如果您通过 Outlook 访问其他邮件后端,则不能使用 Graph,只能使用 OLE。

* Update feb 2021: The SOAP based Exchange Web Services still work, but if you start something new use the REST based Graph API * 2021 年 2 月更新:基于 SOAP 的 Exchange Web 服务仍然有效,但如果您开始新的工作,请使用基于 REST 的 Graph API

You can also use the GCal RESTful API directly.您还可以直接使用 GCal RESTful API。 The Java classes actually just wrap the REST calls. Java 类实际上只是包装了 REST 调用。
And if you created events in Google Calendar you can subscribe to your Google Calendar from Outlook and have your events imported in Outlook too (although you have to use WebDAV for this)如果您在 Google 日历中创建了活动,您可以从 Outlook 订阅您的 Google 日历,并将您的活动也导入到 Outlook 中(尽管您必须为此使用 WebDAV)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM