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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18694607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 10:15:53  来源:igfitidea点击:

How to add events to Outlook Calendar or Google Calendar programmatically?

javaweb-applicationscalendaroutlookgoogle-calendar-api

提问by Noah Martin

I have a Java Web application from which the user can add events with date, subject and description (like tasks). I want to send these events to the user's outlook calendar programmatically. Can anyone help me how to achieve this?

我有一个 Java Web 应用程序,用户可以从中添加带有日期、主题和描述(如任务)的事件。我想以编程方式将这些事件发送到用户的 Outlook 日历。谁能帮助我如何实现这一目标?

PS: If it can be done through Google Calendar tell me how to do that as I am not stuck with outlook :)

PS:如果可以通过谷歌日历完成,请告诉我如何做到这一点,因为我没有坚持使用 Outlook :)

回答by Albert Iordache

Google Calendar seems to be the best choice, as you can use the Google Calendar API. For an example written in Java, look here. Just make sure to note the GCal API usage limits.

Google Calendar 似乎是最佳选择,因为您可以使用Google Calendar API。有关用 Java 编写的示例,请查看此处。请务必注意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 Jpstor java-libpst.

Outlook 似乎没有某种 API,但也许您可以使用或修改Jpstjava-libpst 之类的东西。

回答by Jan Doggen

Albert already answered for Google. For Outlook you use either OLE automationor Exchange web services.

阿尔伯特已经为谷歌回答了。对于 Outlook,您可以使用OLE 自动化Exchange Web 服务

Note that the second option is only for Outlook accounts talking to Exchange Server. If you access other mail backends through Outlook you can't use EWS, only use OLE.

请注意,第二个选项仅适用于与 Exchange Server 通信的 Outlook 帐户。如果您通过 Outlook 访问其他邮件后端,则不能使用 EWS,只能使用 OLE。

回答by tachect

You can also use the GCal RESTful API directly. The Java classes actually just wrap the REST calls.
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)

您还可以直接使用 GCal RESTful API。Java 类实际上只是包装了 REST 调用。
如果您在 Google 日历中创建了活动,您可以从 Outlook 订阅您的 Google 日历,并将您的活动也导入到 Outlook 中(尽管您必须为此使用 WebDAV)

回答by Gabe

You can now use Outlook Calendar REST APIand 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}/eventsa 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": "[email protected]",
        "Name": "Janet Schorr"
      },
      "Type": "Required"
    }
  ]
}