Last active
June 11, 2016 17:52
-
-
Save sgrebnov/d7db0f252ae4cc6e8e50 to your computer and use it in GitHub Desktop.
O365/Outlook Cordova Plugin sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resourceUrl = 'https://outlook.office365.com'; | |
var officeEndpointUrl = 'https://outlook.office365.com/ews/odata'; | |
var TENANT_NAME = '17bf7168-5251-44ed-a3cf-37a5997cc451'; | |
var appId = '3cfa20df-bca4-4131-ab92-626fb800ebb5'; | |
var redirectUrl = "http://test.com"; | |
var authUrl = 'https://login.windows.net/' + TENANT_NAME + '/'; | |
var TEST_USER_ID = ''; | |
// Adding missing types and constructors | |
var ItemHelpers = cordova.require('cordova-plugin-ms-outlook.ItemHelpers'); | |
Microsoft.OutlookServices.BodyType = ItemHelpers.BodyType; | |
Microsoft.OutlookServices.Location = ItemHelpers.Location; | |
Microsoft.OutlookServices.ItemBody = function () { return {} }; | |
Microsoft.OutlookServices.Event = function () { return {} }; | |
Microsoft.OutlookServices.Attendee = function () { return {} }; | |
Microsoft.OutlookServices.EmailAddress = function () { return {} }; | |
var AuthenticationContext = Microsoft.ADAL.AuthenticationContext; | |
var outlookClient = new Microsoft.OutlookServices.Client(officeEndpointUrl, | |
new AuthenticationContext(authUrl), resourceUrl, appId, redirectUrl); | |
// Event body content | |
var eventBody = new Microsoft.OutlookServices.ItemBody(); | |
eventBody.ContentType = Microsoft.OutlookServices.BodyType.HTML; | |
eventBody.Content = "Test Event Body"; | |
// Event attendee. | |
var attendee = new Microsoft.OutlookServices.Attendee(); | |
var emailAddress = new Microsoft.OutlookServices.EmailAddress(); | |
emailAddress.Address = "[email protected]"; | |
attendee.EmailAddress = emailAddress; | |
// Event object. | |
var event = new Microsoft.OutlookServices.Event(); | |
event.Start = new Date().toISOString(); | |
event.End = new Date().toISOString(); | |
event.Subject = "Event Subject"; | |
event.Body = eventBody; | |
event.Attendees = []; | |
event.Attendees.push(attendee); | |
// Event location. | |
event.Location = new Microsoft.OutlookServices.Location(); | |
event.Location.DisplayName = 'Redmond'; | |
// Add event | |
outlookClient.me.calendar.events.addEvent(event).then(function (response) { | |
//app.log("Event Added"); | |
}, function (error) { | |
//app.error(error.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment