Unicode C++
Unicode C++
Get Tasks for User
See more Microsoft Tasks and Plans Examples
Demonstrates how to retrieve a list of plannertask objects assigned to a User.See https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0 for more information.
Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// The Microsoft Planner REST API requires an OAuth2 token with the Group.ReadWrite.All scope.
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.
CkJsonObjectW jsonToken;
success = jsonToken.LoadFile(L"qa_data/tokens/msGraphGroup.json");
if (success == false) {
wprintf(L"%s\n",jsonToken.lastErrorText());
return;
}
http.put_AuthToken(jsonToken.stringOf(L"access_token"));
// Send a GET request to https://graph.microsoft.com/v1.0/me/planner/tasks
const wchar_t *strResponse = http.quickGetStr(L"https://graph.microsoft.com/v1.0/me/planner/tasks");
if (http.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkJsonObjectW json;
json.Load(strResponse);
json.put_EmitCompact(false);
if (http.get_LastStatus() != 200) {
wprintf(L"%s\n",json.emit());
wprintf(L"Failed, response status code = %d\n",http.get_LastStatus());
return;
}
wprintf(L"%s\n",json.emit());
// Sample output:
// (See parsing code below..)
// {
// "value": [
// {
// "createdBy": {
// "user": {
// "id": "6463a5ce-2119-4198-9f2a-628761df4a62"
// }
// },
// "planId": "xqQg5FS2LkCp935s-FIFm2QAFkHM",
// "bucketId": "gcrYAaAkgU2EQUvpkNNXLGQAGTtu",
// "title": "title-value",
// "orderHint": "9223370609546166567W",
// "assigneePriority": "90057581\"",
// "createdDateTime": "2015-03-25T18:36:49.2407981Z",
// "assignments": {
// "fbab97d0-4932-4511-b675-204639209557": {
// "@odata.type": "#microsoft.graph.plannerAssignment",
// "assignedBy": {
// "user": {
// "id": "1e9955d2-6acd-45bf-86d3-b546fdc795eb"
// }
// },
// "assignedDateTime": "2015-03-25T18:38:21.956Z",
// "orderHint": "RWk1"
// }
// },
// "id":"01gzSlKkIUSUl6DF_EilrmQAKDhh"
// }
// ]
// }
int i;
int count_i;
const wchar_t *createdByUserId = 0;
const wchar_t *planId = 0;
const wchar_t *bucketId = 0;
const wchar_t *title = 0;
const wchar_t *orderHint = 0;
const wchar_t *assigneePriority = 0;
const wchar_t *createdDateTime = 0;
const wchar_t *assignments_odataType = 0;
const wchar_t *assignmentsAssignedByUserId = 0;
const wchar_t *assignmentsAssignedDateTime = 0;
const wchar_t *assignmentsOrderHint = 0;
const wchar_t *id = 0;
CkJsonObjectW jsonA;
CkJsonObjectW jsonUserA;
i = 0;
count_i = json.SizeOfArray(L"value");
while (i < count_i) {
json.put_I(i);
createdByUserId = json.stringOf(L"value[i].createdBy.user.id");
planId = json.stringOf(L"value[i].planId");
bucketId = json.stringOf(L"value[i].bucketId");
title = json.stringOf(L"value[i].title");
orderHint = json.stringOf(L"value[i].orderHint");
assigneePriority = json.stringOf(L"value[i].assigneePriority");
createdDateTime = json.stringOf(L"value[i].createdDateTime");
json.ObjectOf2(L"value[i].assignments",jsonA);
const wchar_t *userId = jsonA.nameAt(0);
jsonA.ObjectOf2(userId,jsonUserA);
assignments_odataType = jsonUserA.stringOf(L"\"@odata.type\"");
assignmentsAssignedByUserId = jsonUserA.stringOf(L"assignedBy.user.id");
assignmentsAssignedDateTime = jsonUserA.stringOf(L"assignedDateTime");
assignmentsOrderHint = jsonUserA.stringOf(L"orderHint");
id = json.stringOf(L"value[i].id");
i = i + 1;
}
wprintf(L"Success.\n");
}