How to add events to Outlook Calendar or Google Ca

2019-04-09 06:16发布

问题:

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?

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

回答1:

You can now use Outlook Calendar REST API and send requests from your java code.

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:

{
  "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"
    }
  ]
}


回答2:

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.

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.



回答3:

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

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.



回答4:

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)