Export (0) Print
Expand All

Interacting with calendars (Live Connect API)

Recover your account here

This topic describes how your apps can use the Live Connect APIs to create, read, update, and delete an Outlook.com user's calendars. Your apps can also subscribe to public calendars, such as a list of holidays. The code examples in this topic describe how to do the following tasks.

  • Reading calendar properties
  • Deleting calendars
  • Creating calendars
  • Updating calendar properties
  • Subscribing to public calendars
  • Reading calendar events
  • Deleting calendar events
  • Creating calendar events
  • Updating calendar events

Code examples for these tasks are provided in these languages, which are supported by the Live Connect APIs.

To get the full benefit of the code examples in this topic, you can use them in the context of larger code reference samples that we provide in Working with the code examples. To request the required scopes, see the code patterns in Obtaining user consent.

Specifying a calendar or an event ID

The calendar ID and event ID values used in the path parameters of these code examples are fictitious and won't work in your app. You'll need to replace the values in the path parameter of the examples with a valid ID.

Specifying a calendar ID

In your app, you'll need use a different calendar ID. Here are some examples of calendar IDs:

  • A calendar ID to get info about a calendar.
  • You can reference the signed-in user's calendars by specifying me as the user ID as in:
    • me/calendars to get info about all of the signed-in user's calendars.
  • USER_ID/calendars to get info about all of the calendars for the signed-in user that is represented by USER_ID.

    Note  If USER_ID is not the user who the current access token belongs to, you can get only those calendars that are shared with the current user, not any calendars that the user represented by USER_ID has made publicly available.

You can also use the calendar ID argument to filter the results returned in a collection. For example:

  • Get a limited number of calendar entries by using the limit parameter in the preceding code to specify the number of entries to get. For example, to get the first two calendar entries for the signed-in user, use me/calendars?limit=2.
  • Specify the first calendar entry to get by setting the offset parameter in the preceding code to the index of the first entry that you want to get. For example, to get two calendar entries for the signed-in user, starting at the third calendar entry, use me/calendars?limit=2&offset=3.

    Note  In the JavaScript Object Notation (JSON)-formatted object that's returned, you can look in the paging object for the previous and next structures to get the offset and limit parameter values of the previous and next entries.

Specifying an event ID

In your app, you'll need use a different event ID. Here are some examples of event IDs:

  • An event ID to get info about an event.
  • me/events, to get info about events in all of the signed-in user's calendars.
  • USER_ID/events, to get info about events in all of the calendars for the signed-in user represented by USER_ID.
  • CALENDAR_ID/events, to get info about events in the calendar represented by CALENDAR_ID.

You can also use the calendar ID argument to filter the results returned in a collection. For example:

  • Get a limited number of events based on their starting and ending times in Coordinated Universal Time (UTC) format by using the start_time and end_time parameters in the preceding code. For example, to get all calendar events from August 1 to August 3, inclusive, use CALENDAR_ID/events?start_time=2011-08-01T00:00:00Z&end_time=2011-08-03T00:00:00Z. For info about time formatting options here, see the Creating events section later in this topic.

    Note  If you don't specify the start_time and end_time parameters, you get only those events between the current day and 30 days in the future, by default. If there are no events within this time period, you get an empty result.

Note  You can get info about recurring events. However, you can get only the first occurrence of a recurring event for the specified time period.

Creating events

This section describes the information required to create an event in a calendar. How to do this in an app depends on your app's platform and is illustrated in the following code examples.

Adding an event to a user's calendar requires the wl.calendars_update scope.

Note  To create a calendar event, the corresponding calendar's permissions structure must have a value of owner, co-owner, or read-write.

The start and end times of the event must be expressed in one of these supported formats.

  • Times must begin in one of these formats: yyyy-mm-ddThh:mm:ss, yyyy-mm-ddThh:mm:ss.sss, or yyyy-mm-dd hh:mm:ss. For example, 2011-05-10T14:29:00.000 represents 10 May 2011, at 2:29 P.M.
  • Times must end in one of these formats: +hhmm, -hhmm, +hh:mm, -hh:mm, or Z, which represents the number of hours and minutes as an offset to, or in coordination with, UTC. For example, -0700 represents seven hours preceding UTC. If this time is combined with the preceding example, the result is 2011-05-10T14:29:00.000-0700, or 10 May 2011, at 7:29 A.M.

    Note  If Z is not specified, the time is treated as local time. Also, if end_time is not specified, the default end time is 30 minutes after the specified start_time.

For details about the minimum required and optional structures that your app must provide when using POST, see the "Event object" section in REST reference.

Note  You cannot create recurring events programmatically.

Interacting with calendars in JavaScript and HTML for Windows Store apps

Reading calendar properties in JavaScript

To get info about a calendar, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious calendar ID in the path argument. You'll need to replace the value in the example with a valid calendar ID.


function onReadCalendar() {
    WL.login({
        scope: "wl.calendars"
    }).then(
        function (response) {
            WL.api({
                path: "calendar.a6b2a7e8f2515e5e.c46e5429f0c6451cb469f622b260fa1c",
                method: "GET"
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML =
                        "ID: " + response.id +
                        "<br/>Name: " + response.name;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Deleting calendars in JavaScript

To remove a calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the path argument. You'll need to replace the value in the example with a valid calendar ID.


function onDeleteCalendar() {
    WL.login({
        scope: "wl.calendars_update"
    }).then(
        function (response) {
            WL.api({
                path: "calendar.a6b2a7e8f2515e5e.11a088a04c28495e8672ecf2bf645461",
                method: "DELETE"
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML = "Deleted.";
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Creating calendars in JavaScript

To add a new calendar, use code like this. The wl.calendars_update scope is required.


function onCreateCalendar() {
    WL.login({
        scope: "wl.calendars_update "
    }).then(
        function (response) {
            WL.api({
                path: "me/calendars",
                method: "POST",
                body: {
                    name: "My example calendar"
                }
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML =
                        "ID: " + response.id +
                        "<br/>Name: " + response.name;
                }, 
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Updating calendar properties in JavaScript

To change info for an existing calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the path argument. You'll need to replace the value in the example with a valid calendar ID.


function onUpdateCalendar() {
    WL.login({
        scope: "wl.calendars_update"
    }).then(
        function (response) {
            WL.api({
                path: "calendar.a6b2a7e8f2515e5e.11a088a04c28495e8672ecf2bf645461",
                method: "PUT",
                body: {
                    name: "My example calendar updated"
                }
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML =
                        "ID: " + response.id +
                        "<br/>Name: " + response.name;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                    "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Subscribing to public calendars in JavaScript

To subscribe to a public calendar, use code like the following. The subscription URL must use the webcal scheme, and the calendar file must use the iCalendar format and the file extension .ics. The wl.calendars_update scope is required.


function onSubscribeCalendar() {
    WL.login({
        scope: "wl.calendars_update"
    }).then(
        function (response)
        {
            WL.api({
                path: "me/calendars",
                method: "POST",
                body: {
                    name: "Xbox 360 U.S. Release Schedule",
                    subscription_location: "webcal://www.trulycertifiable.com/calendars/Xbox_360.ics"
                }
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML = "Subscribed.";
                }, 
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed){
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Reading calendar events in JavaScript

To get info about an event, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious event ID in the path argument. You'll need to replace the value in the example with a valid event ID.


function onReadEvent() {
    WL.login({
        scope: "wl.calendars"
    }).then(
        function (response) {
            WL.api({
                path: "event.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20.21e30d8fc00841b8841dd16c7ec7a503",
                method: "GET"
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML =
                        "ID: " + response.id +
                        "<br/>Location: " + response.location;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Deleting calendar events in JavaScript

To remove an event, use code like the following. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the path argument. You'll need to replace the value in the example with a valid event ID.


function onDeleteEvent() {
    WL.login({
        scope: "wl.calendars_update"
    }).then(
        function (response)
        {
            WL.api({
                path: "event.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20.21e30d8fc00841b8841dd16c7ec7a503",
                method: "DELETE"
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML = "Deleted";
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
     );  
}


Creating calendar events in JavaScript

To add a new event in the user's default calendar, use code like this. The wl.events_create scope is required. See Creating events for info about the data formats and required fields.


function onCreateEvent() {
    WL.login({
        scope: "wl.events_create"
    }).then(
        function (response) {
            WL.api({
                path: "me/events",
                method: "POST",
                body: {
                    name: "Family Dinner",
                    description: "Dinner with Cynthia's family",
                    start_time: "2011-12-05T01:30:00-08:00",
                    end_time: "2011-12-05T03:00:00-08:00",
                    location: "Coho Vineyard and Winery, 123 Main St., Redmond WA 19532",
                    is_all_day_event: "false",
                    availability: "busy",
                    visibility: "public"
                }
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML =
                        "ID: " + response.id +
                        "<br/>Name: " + response.name;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Updating calendar events in JavaScript

To change info for an existing event, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the path argument. You'll need to replace the value in the example with a valid event ID.


function onUpdateEvent() {
    WL.login({
        scope: "wl.calendars_update"
    }).then(
        function (response)
        {
            WL.api({
                path: "event.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20.21e30d8fc00841b8841dd16c7ec7a503",
                method: "PUT",
                body: {
                    name: "My example event has changed"
                }
            }).then(
                function (response) {
                    document.getElementById("resultDiv").innerHTML =
                        "ID: " + response.id +
                        "<br/>Name: " + response.name;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed){
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


Top

Interacting with calendars in C# for Windows Store apps and Windows Phone apps

Reading calendar properties in C#

To get info about a calendar, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious calendar ID in the GetAsync call. You'll need to replace the value in the example with a valid calendar ID.


private async void btnReadCalendar_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.GetAsync("calendar.8c8ce076ca27823f.9690899aeeae4e97be18cdc75b644454");
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = "Calendar name: " + result.name;
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error getting calendar info: " + exception.Message;
    }
}


Deleting calendars in C#

To remove a calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the DeleteAsync call. You'll need to replace the value in the example with a valid calendar ID.


private async void btnDeleteCalendar_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.DeleteAsync("calendar.a6b2a7e8f2515e5e.212e9b5c4fce4662bfda971a10519b8b");
        this.infoTextBlock.Text = "Calendar deleted.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error deleting calendar: " + exception.Message;
    }
}


Creating calendars in C#

To add a new calendar, use code like this. The wl.calendars_update scope is required.


private async void btnCreateCalendar_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        var calendar = new Dictionary<string, object>();
        calendar.Add("name", "My Example Calendar");
        LiveOperationResult operationResult = await liveClient.PostAsync("me/calendars", calendar);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Created calendar:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error creating calendar: " + exception.Message;
    }
}


Updating calendar properties in C#

To change info for an existing calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the PutAsync call. You'll need to replace the value in the example with a valid calendar ID.


private async void btnUpdateCalendar_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        var calendar = new Dictionary<string, object>();
        calendar.Add("name", "Roberto's Calendar Updated");
        LiveOperationResult operationResult =
            await liveClient.PutAsync("calendar.8c8ce076ca27823f.9690899aeeae4e97be18cdc75b644454", calendar);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Updated calendar:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error updating calendar: " + exception.Message;
    }
}


Subscribing to public calendars in C#

To subscribe to a public calendar, use code like the following. The subscription URL must use the webcal scheme, and the calendar file must use the iCalendar format and the file extension .ics. The wl.calendars_update scope is required.


private async void btnSubscribe_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        var calendar = new Dictionary<string, object>();
        calendar.Add("name", "Anime/Game Character Birthdays");
        calendar.Add("subscription_url", "webcal://ical.mac.com/fredduck/Anime47Game32Birthdays.ics");
        LiveOperationResult operationResult = await liveClient.PostAsync("me/calendars", calendar);
        this.infoTextBlock.Text = "Calendar subscribed.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error subscribing to calendar: " + exception.Message;
    }
}


Reading calendar events in C#

To get info about an event, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious event ID in the GetAsync call. You'll need to replace the value in the example with a valid event ID.


private async void btnReadEvent_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        var calendar = new Dictionary<string, object>();
        calendar.Add("name", "My Example Calendar");
        LiveOperationResult operationResult =
            await liveClient.GetAsync("event.8c8ce076ca27823f.9690899aeeae4e97be18cdc75b644454.87bfc5dc263c403eacadd35b1e64bdf3");
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = "Event: " + result.name + ", Location: " + result.location;
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error getting event info: " + exception.Message;
    }
}


Deleting calendar events in C#

To remove an event, use code like the following. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the DeleteAsync call. You'll need to replace the value in the example with a valid event ID.


private async void btnDeleteEvent_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.DeleteAsync("event.d050fdffbb314d9bb40bc20a3c961d84.57f866fd013f4a14adcf18d9a9dc23bc");

        this.infoTextBlock.Text = "Event deleted.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error deleting event: " + exception.Message;
    }
}


Creating calendar events in C#

To add a new event in the user's default calendar, use code like this. The wl.events_create scope is required.


private async void btnCreateEvent_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var calEvent = new Dictionary<string, object>();
        calEvent.Add("name", "Family Dinner");
        calEvent.Add("description", "Dinner with Cynthia's family");
        calEvent.Add("start_time", "2012-04-07T01:30:00-08:00");
        calEvent.Add("end_time", "2012-04-07T03:00:00-08:00");
        calEvent.Add("location", "Coho Vineyard and Winery, 123 Main St., Redmond WA 19532");
        calEvent.Add("is_all_day_event", false);
        calEvent.Add("availability", "busy");
        calEvent.Add("visibility", "public");
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult = await liveClient.PostAsync("me/events", calEvent);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Created event:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error creating event: " + exception.Message;
    }
}


Updating calendar events in C#

To change info for an existing event, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the PutAsync call. You'll need to replace the value in the example with a valid event ID.


private async void btnUpdateEvent_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        var calEvent = new Dictionary<string, object>();
        calEvent.Add("name", "My Example Event Has Changed Yet Again");
        LiveOperationResult operationResult =
            await liveClient.PutAsync("event.8c8ce076ca27823f.9690899aeeae4e97be18cdc75b644454.87bfc5dc263c403eacadd35b1e64bdf3", calEvent);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = "Event updated: " + result.name;
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error updating event: " + exception.Message;
    }
}


Top

Interacting with calendars in Objective-C for iOS

Reading calendar properties in Objective-C

To get info about a calendar, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious calendar ID in the getWithPath:delegate: call. You'll need to replace the value in the example with a valid calendar ID.


-(void) getCalendar
{
    [self.liveClient getWithPath:@"calendar.95d463b9efcca0e1.476023a3b4a54f06b7776e21d1b001fa" 
                        delegate:self];
}

-(void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *calendarId = [operation.result objectForKey:@"id"];
    NSString *calendarName = [operation.result objectForKey:@"name"];
    NSString *calendarDescription = [operation.result objectForKey:@"description"];
    self.displayLabel.text = [NSString stringWithFormat:@"Id: %@\n Name: %@\n Description: %@", calendarId, calendarName, calendarDescription];
}


Deleting calendars in Objective-C

To remove a calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the deleteWithPath:delegate: call. You'll need to replace the value in the example with a valid calendar ID.


- (void) deleteCalendar
{
    NSString *calendarId = @"calendar.1234567890";
    [liveClient deleteWithPath:calendarId 
                      delegate:self 
                     userState:@"delete calendar"];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    if ([operation.userState isEqual:@"delete calendar"]) {
        self.statusLabel.text = [NSString stringWithFormat: @"The calendar (%@) was deleted.", operation.path];
    }
}

- (void) liveOperationFailed:(NSError *)error 
                   operation:(LiveOperation *)operation
{
    if ([operation.userState isEqual:@"delete calendar"]) {
        self.statusLabel.text = @"The request to delete the calendar failed.";
    }
}


Creating calendars in Objective-C

To add a new calendar, use code like this. The wl.calendars_update scope is required.


-(void) createCalendar
{
    NSDictionary * newCalendar = [[NSDictionary dictionaryWithObjectsAndKeys:
                                   @"Payments", @"name", 
                                   @"When to pay the bills", @"description",
                                   nil] retain];
    [self.liveClient postWithPath:@"me/calendars" 
                         dictBody:newCalendar 
                         delegate:self
                         userState:@"CREATE_CALENDAR"];
    [newCalendar release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    if (operation.userState == @"CREATE_CALENDAR")
    {
        NSString *calendarId = [operation.result objectForKey:@"id"];
        [self.liveClient getWithPath:calendarId 
                                   delegate:self
                                  userState:@"GET_CALENDAR_INFO"];
    }
    else if (operation.userState == @"GET_CALENDAR_INFO")
    {
        NSString *calendarId = [operation.result objectForKey:@"id"];
        NSString *calendarName = [operation.result objectForKey:@"name"];
        NSString *calendarDescription = [operation.result objectForKey:@"description"];
        self.displayLabel.text = [NSString stringWithFormat:@"Id: %@\n Name: %@\n Description: %@", calendarId, calendarName, calendarDescription];
    }
}


Updating calendar properties in Objective-C

To change info for an existing calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the putWithPath:delegate: call. You'll need to replace the value in the example with a valid calendar ID.


-(void) updateCalendar
{
    NSDictionary * newCalendar = [[NSDictionary dictionaryWithObjectsAndKeys:
                                   @"Updated Calendar Name", @"name", 
                                   @"Description updated...", @"description",
                                   nil] retain];
    [self.liveClient putWithPath:@"calendar.95d463b9efcca0e1.5780dd54f046438687c00e723941dea0" 
                        dictBody:newCalendar 
                        delegate:self];
    [newCalendar release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *calendarId = [operation.result objectForKey:@"id"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:[NSString stringWithFormat:@"Calendar with id: %@ created successfully", calendarId] 
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                           nil];
    [alert show];
    [alert release];
}


Subscribing to public calendars in Objective-C

To subscribe to a public calendar, use code like the following. The subscription URL must use the webcal scheme, and the calendar file must use the iCalendar format and the file extension .ics. The wl.calendars_update scope is required.


- (void) subscribeCalenar
{
    NSDictionary * newCalendar = [[NSDictionary dictionaryWithObjectsAndKeys:
                                   @"US Holidays", @"name", 
                                   @"webcal://ical.mac.com/ical/US32Holidays.ics", @"susbscription_location",
                                   nil] retain];
    [self.liveClient postWithPath:@"me/calendars" 
                         dictBody:newCalendar 
                         delegate:self
                        userState:@"SUBSCRIBE_CALENDAR"];
    [newCalendar release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    if (operation.userState == @"SUBSCRIBE_CALENDAR")
    {
        NSString *calendarId = [operation.result objectForKey:@"id"];
        [self.liveClient getWithPath:calendarId 
                            delegate:self
                           userState:@"GET_CALENDAR_INFO"];
    }
    else if (operation.userState == @"GET_CALENDAR_INFO")
    {
        NSString *calendarId = [operation.result objectForKey:@"id"];
        NSString *calendarName = [operation.result objectForKey:@"name"];
        NSString *calendarDescription = [operation.result objectForKey:@"description"];
        self.displayLabel.text = [NSString stringWithFormat:@"Id: %@\n Name: %@\n Description: %@", calendarId, calendarName, calendarDescription];
    }
}


Reading calendar events in Objective-C

To get info about an event, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious event ID in the getWithPath:delegate: call. You'll need to replace the value in the example with a valid event ID.


-(void) getEvent
    [self.liveClient getWithPath:@"event.95d463b9efcca0e1.5780dd54f046438687c00e723941dea0.d18afec00677494f857e44fe0c6937c7" 
                        delegate:self];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *eventId = [operation.result objectForKey:@"id"];
    NSString *eventName = [operation.result objectForKey:@"name"];
    NSString *eventDescription = [operation.result objectForKey:@"description"];
    NSString *eventLocation = [operation.result objectForKey:@"location"];
    NSString *eventCalendarId = [operation.result objectForKey:@"calendar_id"];
    NSString *eventStartTime = [operation.result objectForKey:@"start_time"];
    NSString *eventEndTime = [operation.result objectForKey:@"end_time"];
    NSString *eventIsAllDay = [operation.result objectForKey:@"is_all_day"];
    NSString *eventRecurrence = [operation.result objectForKey:@"recurrence"];
    NSString *eventAvailability = [operation.result objectForKey:@"availability"];
    NSString *eventVisibility = [operation.result objectForKey:@"visibility"];
    self.displayLabel.text = [NSString stringWithFormat:
                              @"Event Properties:\n"
                              @"\tId. %@\n"
                              @"\tName. %@\n"
                              @"\tDescription. %@\n"
                              @"\tLocation. %@\n"
                              @"\tCalendar Id. %@\n"
                              @"\tStart Time. %@\n"
                              @"\tEnd Time. %@\n"
                              @"\tIs All Day. %@\n"
                              @"\tRecurrence. %@\n"
                              @"\tAvailability. %@\n"
                              @"\tVisibility. %@"
                              , eventId, 
                              eventName, 
                              eventDescription, 
                              eventLocation, 
                              eventCalendarId, 
                              eventStartTime,
                              eventEndTime,
                              eventIsAllDay,
                              eventRecurrence,
                              eventAvailability,
                              eventVisibility];
    
}


Deleting calendar events in Objective-C

To remove an event, use code like the following. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the deleteWithPath:delegate: call. You'll need to replace the value in the example with a valid event ID.


- (void) deleteEvent
{
    [self.liveClient deleteWithPath:@"event.95d463b9efcca0e1.5780dd54f046438687c00e723941dea0.d18afec00677494f857e44fe0c6937c7" 
                           delegate:self];

}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:@"Event was deleted successfully!"
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                          nil];
    [alert show];
    [alert release];
}


Creating calendar events in Objective-C

To add a new event in the user's default calendar, use code like this. The wl.events_create scope is required. See Creating events for info on the data formats and required fields.


-(void) createEvent
{
    NSDictionary * newEvent = [[NSDictionary dictionaryWithObjectsAndKeys:
                                @"John's Bday", @"name", 
                                @"BBQ @ his place", @"description",
                                @"2012-01-12T21:00:00+00:00",@"start_time",
                                @"2012-01-13T03:00:00+00:00",@"end_time",
                                @"John's Pad",@"location",
                                @"busy",@"availability",
                                @"2012-01-12T21:00:00+00:00",@"start_time",
                                nil] retain];
    [self.liveClient postWithPath:@"me/events" 
                         dictBody:newEvent 
                         delegate:self];
    [newEvent release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *eventId = [operation.result objectForKey:@"id"];
    NSString *eventName = [operation.result objectForKey:@"name"];
    NSString *eventDescription = [operation.result objectForKey:@"description"];
    NSString *eventLocation = [operation.result objectForKey:@"location"];
    NSString *eventCalendarId = [operation.result objectForKey:@"calendar_id"];
    NSString *eventStartTime = [operation.result objectForKey:@"start_time"];
    NSString *eventEndTime = [operation.result objectForKey:@"end_time"];
    NSString *eventIsAllDay = [operation.result objectForKey:@"is_all_day"];
    NSString *eventRecurrence = [operation.result objectForKey:@"recurrence"];
    NSString *eventAvailability = [operation.result objectForKey:@"availability"];
    NSString *eventVisibility = [operation.result objectForKey:@"visibility"];
    self.displayLabel.text = [NSString stringWithFormat:
                              @"Event Properties:\n"
                              @"\tId. %@\n"
                              @"\tName. %@\n"
                              @"\tDescription. %@\n"
                              @"\tLocation. %@\n"
                              @"\tCalendar Id. %@\n"
                              @"\tStart Time. %@\n"
                              @"\tEnd Time. %@\n"
                              @"\tIs All Day. %@\n"
                              @"\tRecurrence. %@\n"
                              @"\tAvailability. %@\n"
                              @"\tVisibility. %@"
                              , eventId, 
                              eventName, 
                              eventDescription, 
                              eventLocation, 
                              eventCalendarId, 
                              eventStartTime,
                              eventEndTime,
                              eventIsAllDay,
                              eventRecurrence,
                              eventAvailability,
                              eventVisibility];
}


Updating calendar events in Objective-C

To change info for an existing event, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the putWithPath:delegate: call. You'll need to replace the value in the example with a valid event ID.


-(void) updateEvent
{
    NSDictionary * updatedEvent = [[NSDictionary dictionaryWithObjectsAndKeys:
                                    @"BBQ Grill @ Smith Street. (Updated location)",@"location",
                                    @"2012-01-12T20:30:00+00:00",@"start_time",
                                    nil] retain];
    [self.liveClient putWithPath:@"event.95d463b9efcca0e1.88c4c26007194319a717a8aa8f51fb00.1c1d09bb0d7743e2b32a97f419632061" 
                        dictBody:updatedEvent 
                        delegate:self];
    [updatedEvent release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:@"Event was updated successfully!"
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                          nil];
    [alert show];
    [alert release];
}


Top

Interacting with calendars in Java for Android

Reading calendar properties in Java

To get info about a calendar, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious calendar ID in the getAsync call. You'll need to replace the value in the example with a valid calendar ID.


public void readCalendar() {
    final String calendarId = "calendar.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20";
       final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error getting calendar info: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            resultTextView.setText("Calendar info:" + 
                "\n ID = " + result.optString("id") + 
                "\nName = " + result.optString("name") + 
                "\nPermissions = " + result.optString("permissions"));
        }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.calendars" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                   client.getAsync(calendarId, opListener);                    
               }
        }
    );
}


Deleting calendars in Java

To remove a calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the deleteAsync call. You'll need to replace the value in the example with a valid calendar ID.


public void deleteCalendar() {
    client.deleteAsync("calendar.a6b2a7e8f2515e5e.f69bbd89e2cd42859a8e44a36f9e8f7d", new LiveOperationListener() {
        public void onComplete(LiveOperation operation) {
            resultTextView.setText("Calendar deleted.");
        }
        public void onError(LiveOperationException exception, LiveOperation operation) {
            resultTextView.setText("Error deleting calendar: " + exception.getMessage());
        }
    });
}


Creating calendars in Java

To add a new calendar, use code like this. The wl.calendars_update scope is required.


public void createCalendar() {
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error creating calendar: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Calendar created:\n" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.calendars_update" }), new LiveAuthListener() {
           public void onAuthError(LiveAuthException exception, Object userState) {
            resultTextView.setText("Error signing in: " + exception.getMessage());
         }
        public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
            try {
                JSONObject body = new JSONObject();
                body.put("name", "My New Calendar");
                body.put("description", "Manage some new calendar events");
                client.postAsync("me/calendars", body, opListener);    
            }
            catch(JSONException ex) {
                resultTextView.setText("Error building calendar: " + ex.getMessage());
            }
           }
    });
}


For details about the minimum required and optional structures that your app must provide when using POST, see the "Calendar object" section in REST reference.

Updating calendar properties in Java

To change info for an existing calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the putAsync call. You'll need to replace the value in the example with a valid calendar ID.


public void updateCalendar() {
    final String calendarId = "calendar.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20";
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
            resultTextView.setText("Error updating calendar: " + exception.getMessage());
        }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Calendar updated:\n" +
                "\nID = " + result.optString("id") +
                "\rName = " + result.optString("name");
            resultTextView.setText(text);
        }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.calendars_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("name", "My Updated Calendar");
                       client.putAsync(calendarId, body, opListener);    
                }
                catch(JSONException ex) {
                    resultTextView.setText("Error updating calendar: " + ex.getMessage());
                }
               }
        }
    );
}


Note  To update a calendar's properties, the calendar's permissions structure must have a value of owner, co-owner, or read-write.

For details about the minimum required and optional structures that your app must provide when using PUT, see the "Calendar object" section in REST reference.

Subscribing to public calendars in Java

To subscribe to a public calendar, use code like the following. The subscription URL must use the webcal scheme, and the calendar file must use the iCalendar format and the file extension .ics. The wl.calendars_update scope is required.


public void subscribeCalendar() {
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error subscribing to calendar: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Calendar subscribed:\n" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.calendars_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("name", "US Holidays");
                    body.put("subscription_location", "webcal://ical.mac.com/ical/US32Holidays.ics");
                       client.postAsync("me/calendars", body, opListener);    
                }
                catch(JSONException ex) {
                    resultTextView.setText("Error subscribing to calendar: " + ex.getMessage());
                }
               }
        }
    );   
}


Reading calendar events in Java

To get info about an event, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious event ID in the getAsync call. You'll need to replace the value in the example with a valid event ID.


public void readEvent() {
    final String eventId = "event.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20.e671b72b6a024b67ace52e88f7185f36";
    client.getAsync(eventId, new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error reading event: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Event info:" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name") +
                "\nLocation = " + result.optString("location") +
                "\nDescription = " + result.optString("description") +
                "\nStart time = " + result.optString("start_time") +
                "\nEnd time = " + result.optString("end_time") +
                "\nAll day event = " + result.optString("is_all_day_event") +
                "\nRecurrence = " + result.optString("recurrence");
               resultTextView.setText(text);
           }
       });
}


Deleting calendar events in Java

To remove an event, use code like the following. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the deleteAsync call. You'll need to replace the value in the example with a valid event ID.


public void deleteEvent() {
    String eventId = "event.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20.2f136a42169a4fc9903652a8fbade918";
    client.deleteAsync(eventId, new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error deleting event: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            resultTextView.setText("Event deleted.");
           }
       });
}


Creating calendar events in Java

To add a new event in the user's default calendar, use code like this. The wl.events_create scope is required. See Creating events for info on the data formats and required fields.


public void createEvent() {
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error creating event: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Event created:\n" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.calendars_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("name", "Family Dinner");
                    body.put("description", "Dinner with Cynthia's family");
                    body.put("start_time", "2012-01-22T01:30:00-08:00");
                    body.put("end_time", "2012-01-22T03:00:00-08:00");
                    body.put("location", "Coho Vineyard and Winery, 123 Main St., Redmond WA 19532");
                    body.put("is_all_day_event", false);
                    body.put("availability", "busy");
                    body.put("visibility", "public");
                       client.postAsync("me/events", body, opListener);    
                }
                catch(JSONException ex) {
                    resultTextView.setText("Error building event: " + ex.getMessage());
                }
               }
        }
    );               
}


Updating calendar events in Java

To change info for an existing event, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the putAsync call. You'll need to replace the value in the example with a valid event ID.


public void updateEvent() {
    final String eventId = "event.a6b2a7e8f2515e5e.16c27f2b66ac4ffdae6d59236b692e20.e671b72b6a024b67ace52e88f7185f36";
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error updating event: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Event updated:\n" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.calendars_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("name", "Family dinner with some guests");
                       client.putAsync(eventId, body, opListener);    
                }
                catch(JSONException ex) {
                    resultTextView.setText("Error updating event: " + ex.getMessage());
                }
               }
        }
    );
}


Note  To update a calendar event, the corresponding calendar's permissions structure must have a value of owner, co-owner, or read-write.

For details about the required and optional structures that your app must provide when using PUT, see the "Event object" section in REST reference.

Note  You cannot update recurring events programmatically.

Top

Interacting with calendars using REST

Reading calendar properties using REST

To get info about a calendar, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious calendar ID in the URL. You'll need to replace the value in the example with a valid calendar ID.

GET https://apis.live.net/v5.0/calendar.611afb17fa9448f28cdb8277e8ffeb77?access_token=ACCESS_TOKEN

Deleting calendars using REST

To remove a calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the URL. You'll need to replace the value in the example with a valid calendar ID.

DELETE https://apis.live.net/v5.0/calendar.611afb17fa9448f28cdb8277e8ffeb77?access_token=ACCESS_TOKEN

Creating calendars using REST

To add a new calendar, use code like this. The wl.calendars_update scope is required.

POST https://apis.live.net/v5.0/me/calendars

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example calendar"
}

Updating calendar properties using REST

To change info for an existing calendar, use code like this. The wl.calendars_update scope is required.

Note  This code example uses a fictitious calendar ID in the URL. You'll need to replace the value in the example with a valid calendar ID.

PUT https://apis.live.net/v5.0/calendar.611afb17fa9448f28cdb8277e8ffeb77

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example calendar has changed"
}

Subscribing to public calendars using REST

To subscribe to a public calendar, use code like the following. The subscription URL must use the webcal scheme, and the calendar file must use the iCalendar format and the file extension .ics. The wl.calendars_update scope is required.

POST https://apis.live.net/v5.0/me/calendars

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "Anime/game character birthdays",
    "subscription_location": "webcal://ical.mac.com/fredduck/Anime47Game32Birthdays.ics"
}

Reading calendar events using REST

To get info about an event, use code like this. The wl.calendars scope is required.

Note  This code example uses a fictitious event ID in the URL. You'll need to replace the value in the example with a valid event ID.

GET https://apis.live.net/v5.0/event.c76d2a8c4e674ff9bc96f17dee3c34c9.b987b00b77194723b8c16bbe57a03037?access_token=ACCESS_TOKEN

Deleting calendar events using REST

To remove an event, use code like the following. The wl.calendars_update scope is required.

Note  This code example uses a fictitious event ID in the URL. You'll need to replace the value in the example with a valid event ID.

DELETE https://apis.live.net/v5.0/event.c76d2a8c4e674ff9bc96f17dee3c34c9.b987b00b77194723b8c16bbe57a03037?access_token=ACCESS_TOKEN

Creating calendar events using REST

To add a new event in the user's default calendar, use code like this. The wl.events_create scope is required. See Creating events for info on the data formats and required fields.

POST https://apis.live.net/v5.0/me/events 

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name: "Family Dinner",
    "description": "Dinner with Cynthia's family",
    "start_time": "2011-03-22T01:30:00-08:00",
    "end_time": "2011-03-22T03:00:00-08:00",
    "location": "Coho Vineyard and Winery, 123 Main St., Redmond WA 19532",
    "is_all_day_event": false,
    "availability": "busy",
    "visibility": "public"
}

Updating calendar events using REST

Note  This code example uses a fictitious event ID in the URL. You'll need to replace the value in the example with a valid event ID.

PUT https://apis.live.net/v5.0/event.c76d2a8c4e674ff9bc96f17dee3c34c9.b987b00b77194723b8c16bbe57a03037

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example event has changed"
}

Top

 

 

Show:
© 2014 Microsoft