Task Management in Cloud Calendars


Requirements: Cloud Calendars

Introduction

Cloud Calendars provides a suite of easy-to-use task and task list management components. This article covers task management in popular cloud services such as Office365 (Graph API) and Google.

Contents

GoogleTasks

The GoogleTasks component provides an easy-to-use interface to manage Google Tasks using Google's REST API. The GoogleTasks component supports listing tasks and task lists as well as creating, updating, and deleting both tasks and task lists.

OAuth Authentication

Before using the component, an OAuth token must be provided through the Authorization property. The OAuth component included in the toolkit can be used to assist in this process.

By design, user interaction is required to fetch an OAuth authorization string the first time. A user must be directed to a URL where they will authenticate and grant access to the connecting application. The user is then redirected back to the application along with a code that will be exchanged for an authorization string by the OAuth component. The authorization string is then used in requests to the cloud service.

The authorization string is valid only for a limited period of time; however, a parameter can be included in the initial authorization to request a refresh token that can be used without user interaction to update the authorization token. To add a parameter, the AddParam method can be used. In the following example, the "access_type" parameter is set to "offline".

Fetching an OAuth Authorization String Using the OAuth Component: Oauth oauth = new Oauth(); oauth.ClientId = "CLIENT_ID"; // This is for testing purposes only oauth.ClientSecret = "CLIENT_SECRET"; // This is for testing purposes only oauth.ServerAuthURL = "https://accounts.google.com/o/oauth2/auth"; oauth.ServerTokenURL = "https://accounts.google.com/o/oauth2/token"; oauth.AuthorizationScope = "https://www.googleapis.com/auth/tasks.readonly https://www.googleapis.com/auth/tasks"; oauth.GrantType = OauthGrantTypes.ogtAuthorizationCode; oauth.AddParam("access_type", "offline"); googletask.Authorization = oauth.GetAuthorization();

Creating Task Lists

Use the CreateTaskList method to create a new task list. After creating a task list with a title, you can update its title by editing the task list in the TaskLists collection and calling the UpdateTaskList method.

Creating a Task List: // Create a Task List googletask.CreateTaskList("My personal Task List"); // Set properties to update googletask.TaskLists[0].Title = "My personal Task List 2"; // Update the Task List googletask.UpdateTaskList(0);

Listing Task Lists

Task lists for the user can be retrieved using the ListTaskLists method. The TaskListList event will fire for each task list, and the TaskLists collection will be populated when the method returns. If the number of task lists exceeds the page size, the ListTaskListsMarker will be populated. You can call ListTaskLists again to retrieve the next page of task lists. These task lists will be added to the end of the TaskLists collection.

Listing a Task List: do { googletask.ListTaskLists(); } while (googletask.Config("ListTaskListsMarker").Length > 0);

Deleting Task Lists

Task Lists for the user can be deleted using the DeleteTaskList method.

Deleting a Task List: // List task lists and delete the task list named "new name" googletask.ListTaskLists(); for (int i = 0; i < googletask.TaskLists.Count; i++) { if (googletask.TaskLists[i].DisplayName == "new name") { googletask.DeleteTaskList(googletask.TaskLists[i].Id); break; } // Note: the component would let you name more than one task list with the same name so the example would delete the first encounter with the task list that has the specified name }

Creating Tasks

Use the CreateTask method to create a new task. The newly created task is added at the beginning of the Tasks collection. After creating the task with basic information, you can update it and set additional fields by editing the task in the Tasks collection and calling the UpdateTask method.

Creating a Task: googletask.CreateTask("Ben's task",taskListId); // Set properties to update googletask.Tasks[0].Title = "John's Friday Task"; googletask.Tasks[0].Notes = "Notes..."; // Update the task googletask.UpdateTask(0);

Listing Tasks

Tasks for a specific task list can be retrieved using the ListTasks method. The TaskList event will fire for each task, and the Tasks collection will be populated once the method returns. If the number of tasks exceeds the page size, the ListTasksMarker will be populated. You can call ListTasks again to retrieve the next page of tasks. These tasks will be added at the end of the Tasks collection.

Listing a Task: do { googletask.ListTasks(taskListId); } while (googletask.ListTasksMarker.Length > 0); A specific task can also be retrieved using the GetTask method.

Retrieving a Task by ID: // Retrieve an task by its ID string taskListId = "12345"; // Replace with the actual task list ID string taskId = "54321"; // Replace with the actual task ID googletask.GetTask(taskListId, taskId); // Access the retrieved task GTTaskItem retrievedTask = googletask.Tasks[0]; retrievedTask.Title; // task name retrievedTask.Notes; // notes for the task

Deleting Tasks

Tasks for the user can be deleted using the DeleteTask method.

Deleting a Task: // List tasks and delete all tasks containing "Meeting" in their name googletask.ListTasks(taskListId); for (int i = 0; i < googletask.Tasks.Count; i++) { if (googletask.Tasks[i].Title.Contains("Meeting")) { googletask.DeleteTask(taskListId, googletask.Tasks[i].Id); } }

Office365Tasks

The Office365Tasks component provides an easy-to-use interface to manage task lists and tasks using Microsoft's Graph API. The Office365Tasks component supports listing tasks and task lists as well as creating, updating, and deleting both tasks and task lists.

OAuth Authentication

Before using the component, an OAuth token must be provided through the Authorization property. The OAuth component included in the toolkit can be used to assist in this process.

By design, user-interaction is required to fetch an OAuth authorization string the first time. A user must be directed to a URL where they will authenticate and grant access to the connecting application. The user is then redirected back to the application along with a code that will be exchanged for an authorization string by the OAuth component. The authorization string is then used in requests to the cloud service.

The authorization string is valid only for a limited period of time; however, a parameter can be included in the initial authorization to request a refresh token that can be used without user interaction to update the authorization token.

Fetching an OAuth Authorization String Using the OAuth Component: Oauth oauth = new Oauth(); oauth.ClientId = "CLIENT_ID"; // This is for testing purposes only oauth.ClientSecret = "CLIENT_SECRET"; // This is for testing purposes only oauth.ServerAuthURL = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"; oauth.ServerTokenURL = "https://login.microsoftonline.com/common/oauth2/v2.0/token"; oauth.AuthorizationScope = "offline_access tasks.readwrite user.read"; oauth.GrantType = OauthGrantTypes.ogtAuthorizationCode; office365task.Authorization = oauth.GetAuthorization();

Creating Task Lists

Use the CreateTaskList method to create a new task list. After creating a task list with a display name, you can update its fields by editing the task list in the TaskLists collection and calling the UpdateTaskList method.

Creating and Updating a Task List: office365task.CreateTaskList("My Task List"); // Set properties to update office365task.TaskLists[0]DisplayName = "New name"; office365task.UpdateTaskList(0);

Listing Task Lists

Task Lists for the user can be retrieved using the ListTaskLists method. The TaskListsList event will fire for each task list, and the TaskLists collection will be populated when the method returns. If the number of task lists exceeds the page size, the ListTaskListsMarker will be populated. You can call ListTaskLists again to retrieve the next page of task lists. These task lists will be added to the end of the TaskLists collection.

Listing a Task List: do { office365task.ListTaskLists(); } while (office365task.Config("ListTaskListsMarker").Length > 0);

Deleting Task Lists

Task Lists for the user can be deleted using the DeleteTaskList method.

Deleting a Task List: // List task lists and deleting the task list named "new name" office365task.ListTaskLists(); for (int i = 0; i < office365task.TaskLists.Count; i++) { if (office365task.TaskLists[i].DisplayName == "new name") { office365task.DeleteTaskList(office365task.TaskLists[i].Id); break; } // Note: the component would let you name more than one task list with the same name so the example would delete the first encounter with the task list that has the specified name }

Creating Tasks

Use the CreateTask method to create a new task. The newly created task is added at the beginning of the Tasks collection. After creating the task with basic information, you can update it and set additional fields by editing the task in the Tasks collection and calling the UpdateTask method.

Creating a Task: // Create new task office365task.CreateTask("My task", office365task.TaskLists[0].Id); // Set properties to update office365task.Tasks[0].Title = "new title"; office365task.Tasks[0].Categories = "new category"; office365task.Tasks[0].Importance = TOTImportances.otiNormal; office365task.Tasks[0].IsReminderOn = true; office365task.UpdateTask(0);

Listing Tasks

Tasks for a specific task list can be retrieved using the ListTasks method. The TaskList event will fire for each task, and the Tasks collection will be populated once the method returns. If the number of tasks exceeds the page size, the ListTasksMarker will be populated. You can call ListTasks again to retrieve the next page of tasks. These tasks will be added at the end of the Tasks collection.

Listing a Task: do { office365task.ListTasks(office365task.TaskLists[0].Id); } (office365task.ListTasksMarker.Length > 0);

A specific task can also be retrieved using the GetTask method.

Retrieving a Task by ID: // Retrieve a task by its ID string taskId = "12345"; // Replace with the actual task ID string taskListId = "54321" // Replace with the actual task list ID office365task.GetTask(taskListId, taskId); // Access the retrieved task OTTaskItem retrievedTask = office365task.Tasks[0]; retrievedTask.Title; // task title retrievedTask.Importance; // task Importance retrievedTask.StartDateTime; // start time of task office365task.GetTaskField(0, "/json/status"); // task status office365task.GetTaskField(0, "/json/dueDateTime/dateTime"); // due date time

Deleting Tasks

Tasks for the user can be deleted using the DeleteTask method.

Deleting a Task: // List tasks and deleting the task named "new title" office365task.ListTasks(office365task.TaskLists[0].Id); for (int i = 0; i < office365task.Tasks.Count; i++) { if (office365task.Tasks[i].Title == "new title") { office365task.DeleteTask(office365task.TaskLists[0].Id, office365task.Task[i].Id); break; } // Note: the component would let you name more than one task with the same name so the example would delete the first encounter with the task that has the specified name }

Creating Checklist Items

Use the CreateCheckListItem method to create a new checklist item. The newly created task is added at the beginning of the CheckListItems collection. After creating the checklist item with basic information, you can update it and set additional fields by editing the checklist item in the CheckListItems collection and calling the UpdateCheckListItem method.

Creating a Checklist Item: office365task.CreateTaskList("My task list"); office365task.CreateTask("My task", office365task.TaskLists[0].Id); //creating a task named "My task" inside the "My task list" task list office365task.CreateCheckListItem("My checklist item", office365task.TaskLists[0].Id, office365task.Tasks[0].Id); // creating a checklist item named "My checklist item" inside the "My task" task // Set properties to update office365task.CheckListItems[0].DisplayName = "New name"; office365task.CheckListItems[0].IsChecked= true; office365task.UpdateCheckListItem(0);

Listing CheckList Items

Checklist items for a specific task can be retrieved using the ListCheckListItems method. The CheckListItemList event will fire for each checklist item, and the CheckListItems collection will be populated once the method returns.

Listing a Checklist Item: office365task.ListCheckListItems(office365task.TaskLists[0].Id, office365task.Tasks[0].Id);

A specific checklist item can also be retrieved using the GetCheckListItem method.

Retrieving a Checklist Item by ID: // Retrieve a checklist item by its ID string taskId = "12345"; // Replace with the actual task ID string taskListId = "54321" // Replace with the actual task list ID string checkListItemId = "543123" // Replace with the actual checklist item ID office365task.GetCheckListItem(taskListId, taskId, checkListItemId); // Access the retrieved checklist item OTCheckListItem retrievedChecklistItem = office365task.CheckListItems[0]; retrievedChecklistItem.DisplayName; // task title retrievedChecklistItem.IsChecked; // if checklist item is checked retrievedChecklistItem.CreatedDateTime; // checklist item creation time

Deleting Checklist Items

Checklist items for the user can be deleted using the DeleteCheckListItem method.

Deleting a Checklist Item: // List checklist items and deleting the checklist item named "new name" office365task.ListCheckListItems(office365task.TaskLists[0].Id, office365task.Tasks[0].Id); for (int i = 0; i < office365task.CheckListItems.Count; i++) { if if (office365task.CheckListItems[i].DisplayName == "new name") { office365task.DeleteCheckListItem(office365task.TaskLists[0].Id, office365task.Tasks[0].Id, office365task.CheckListItems[i].Id); break; } // Note: the component would let you name more than one checklist item with the same name so the example would delete the first encounter with the checklist item that has the specified name }

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.