Unicode C
Unicode C
Retrieve the metadata for a DriveItem
See more OneDrive Examples
Fetches the JSON metadata for a DriveItem.Chilkat Unicode C Downloads
#include <C_CkJsonObjectW.h>
#include <C_CkHttpW.h>
void ChilkatSample(void)
{
BOOL success;
HCkJsonObjectW json;
HCkHttpW http;
const wchar_t *metaData;
const wchar_t *odata_context;
const wchar_t *microsoft_graph_downloadUrl;
const wchar_t *createdDateTime;
const wchar_t *cTag;
const wchar_t *eTag;
const wchar_t *id;
const wchar_t *lastModifiedDateTime;
const wchar_t *name;
int size;
const wchar_t *webUrl;
int ratingRating;
int ratingSimpleRating;
const wchar_t *createdByUserDisplayName;
const wchar_t *createdByUserId;
const wchar_t *lastModifiedByUserDisplayName;
const wchar_t *lastModifiedByUserId;
const wchar_t *parentReferenceDriveId;
const wchar_t *parentReferenceDriveType;
const wchar_t *parentReferenceId;
const wchar_t *parentReferenceName;
const wchar_t *parentReferencePath;
const wchar_t *fileMimeType;
const wchar_t *fileHashesSha1Hash;
const wchar_t *fileSystemInfoCreatedDateTime;
const wchar_t *fileSystemInfoLastModifiedDateTime;
int imageHeight;
int imageWidth;
const wchar_t *photoTakenDateTime;
const wchar_t *sharedScope;
const wchar_t *sharedOwnerUserDisplayName;
const wchar_t *sharedOwnerUserId;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Use your client ID, client secret, and tenant ID in the following lines
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"client_id",L"2871da2c-8176-4b7f-869b-2311aa82e743");
CkJsonObjectW_UpdateString(json,L"client_secret",L"2hu9Q~r5QuryUcEkNbg1btLtnfU1VUXzhSCG6brH");
CkJsonObjectW_UpdateString(json,L"scope",L"https://graph.microsoft.com/.default");
CkJsonObjectW_UpdateString(json,L"token_endpoint",L"https://login.microsoftonline.com/114d7ed6-71bf-4dbe-a866-748364121bf2/oauth2/v2.0/token");
http = CkHttpW_Create();
CkHttpW_putAuthToken(http,CkJsonObjectW_emit(json));
// Sends the following GET request:
// GET https://graph.microsoft.com/v1.0/users/{user-id}/drive/root:/{item-path}
// Make sure to automatically follow redirects
CkHttpW_putFollowRedirects(http,TRUE);
// This example will get the metadata for /Misc/wildlife/penguins.jpg
CkHttpW_SetUrlVar(http,L"item_path",L"Misc//penguins.jpg");
CkHttpW_SetUrlVar(http,L"user_id",L"4fe732c3-322e-4a6b-b729-2fd1eb5c6104");
metaData = CkHttpW_quickGetStr(http,L"https://graph.microsoft.com/v1.0/users/{$user_id}/drive/root:/{$item_path}");
if (CkHttpW_getLastMethodSuccess(http) != TRUE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkJsonObjectW_Dispose(json);
CkHttpW_Dispose(http);
return;
}
CkJsonObjectW_putEmitCompact(json,FALSE);
success = CkJsonObjectW_Load(json,metaData);
wprintf(L"%s\n",CkJsonObjectW_emit(json));
// Sample JSON metadata result:
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/drive/root/$entity",
// "@microsoft.graph.downloadUrl": "https://public.dm.files.1drv.com/y4mh0z_Og97O7Q...o2q1HhNBU",
// "createdDateTime": "2017-06-04T20:40:22.48Z",
// "cTag": "aYzozQTMzRkNFQjlCNzRDQzE1ITQ4NzIuMjU3",
// "eTag": "aM0EzM0ZDRUI5Qjc0Q0MxNSE0ODcyLjY",
// "id": "3A33FCEB9B74CC15!4872",
// "lastModifiedDateTime": "2018-10-20T18:22:29.977Z",
// "name": "penguins.jpg",
// "size": 777835,
// "webUrl": "https://1drv.ms/i/s!ABXMdJvr_DM6pgg",
// "rating": {
// "rating": 75,
// "simpleRating": 4
// },
// "createdBy": {
// "user": {
// "displayName": "Joe Programmer",
// "id": "3a33fceb9b74cc15"
// }
// },
// "lastModifiedBy": {
// "user": {
// "displayName": "Joe Programmer",
// "id": "3a33fceb9b74cc15"
// }
// },
// "parentReference": {
// "driveId": "3a33fceb9b74cc15",
// "driveType": "personal",
// "id": "3A33FCEB9B74CC15!4871",
// "name": "wildlife",
// "path": "/drive/root:/Misc/wildlife"
// },
// "file": {
// "mimeType": "image/jpeg",
// "hashes": {
// "sha1Hash": "DF7BE9DC4F467187783ACA68C7CE98E4DF2172D0"
// }
// },
// "fileSystemInfo": {
// "createdDateTime": "2017-06-04T20:40:22.48Z",
// "lastModifiedDateTime": "2009-07-14T05:32:31.674Z"
// },
// "image": {
// "height": 768,
// "width": 1024
// },
// "photo": {
// "takenDateTime": "2008-02-18T05:07:31Z"
// },
// "shared": {
// "scope": "users",
// "owner": {
// "user": {
// "displayName": "Joe Programmer",
// "id": "3a33fceb9b74cc15"
// }
// }
// }
// }
//
// If the response status code was not 200, then it failed.
if (CkHttpW_getLastStatus(http) != 200) {
wprintf(L"Response Status Code = %d\n",CkHttpW_getLastStatus(http));
wprintf(L"Failed.\n");
CkJsonObjectW_Dispose(json);
CkHttpW_Dispose(http);
return;
}
// Demonstrate how to parse the JSON...
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
odata_context = CkJsonObjectW_stringOf(json,L"\"@odata.context\"");
microsoft_graph_downloadUrl = CkJsonObjectW_stringOf(json,L"\"@microsoft.graph.downloadUrl\"");
createdDateTime = CkJsonObjectW_stringOf(json,L"createdDateTime");
cTag = CkJsonObjectW_stringOf(json,L"cTag");
eTag = CkJsonObjectW_stringOf(json,L"eTag");
id = CkJsonObjectW_stringOf(json,L"id");
lastModifiedDateTime = CkJsonObjectW_stringOf(json,L"lastModifiedDateTime");
name = CkJsonObjectW_stringOf(json,L"name");
size = CkJsonObjectW_IntOf(json,L"size");
webUrl = CkJsonObjectW_stringOf(json,L"webUrl");
ratingRating = CkJsonObjectW_IntOf(json,L"rating.rating");
ratingSimpleRating = CkJsonObjectW_IntOf(json,L"rating.simpleRating");
createdByUserDisplayName = CkJsonObjectW_stringOf(json,L"createdBy.user.displayName");
createdByUserId = CkJsonObjectW_stringOf(json,L"createdBy.user.id");
lastModifiedByUserDisplayName = CkJsonObjectW_stringOf(json,L"lastModifiedBy.user.displayName");
lastModifiedByUserId = CkJsonObjectW_stringOf(json,L"lastModifiedBy.user.id");
parentReferenceDriveId = CkJsonObjectW_stringOf(json,L"parentReference.driveId");
parentReferenceDriveType = CkJsonObjectW_stringOf(json,L"parentReference.driveType");
parentReferenceId = CkJsonObjectW_stringOf(json,L"parentReference.id");
parentReferenceName = CkJsonObjectW_stringOf(json,L"parentReference.name");
parentReferencePath = CkJsonObjectW_stringOf(json,L"parentReference.path");
fileMimeType = CkJsonObjectW_stringOf(json,L"file.mimeType");
fileHashesSha1Hash = CkJsonObjectW_stringOf(json,L"file.hashes.sha1Hash");
fileSystemInfoCreatedDateTime = CkJsonObjectW_stringOf(json,L"fileSystemInfo.createdDateTime");
fileSystemInfoLastModifiedDateTime = CkJsonObjectW_stringOf(json,L"fileSystemInfo.lastModifiedDateTime");
imageHeight = CkJsonObjectW_IntOf(json,L"image.height");
imageWidth = CkJsonObjectW_IntOf(json,L"image.width");
photoTakenDateTime = CkJsonObjectW_stringOf(json,L"photo.takenDateTime");
sharedScope = CkJsonObjectW_stringOf(json,L"shared.scope");
sharedOwnerUserDisplayName = CkJsonObjectW_stringOf(json,L"shared.owner.user.displayName");
sharedOwnerUserId = CkJsonObjectW_stringOf(json,L"shared.owner.user.id");
CkJsonObjectW_Dispose(json);
CkHttpW_Dispose(http);
}