C
C
Retrieve the metadata for a DriveItem
See more OneDrive Examples
Fetches the JSON metadata for a DriveItem.Chilkat C Downloads
#include <C_CkJsonObject.h>
#include <C_CkHttp.h>
void ChilkatSample(void)
{
BOOL success;
HCkJsonObject json;
HCkHttp http;
const char *metaData;
const char *odata_context;
const char *microsoft_graph_downloadUrl;
const char *createdDateTime;
const char *cTag;
const char *eTag;
const char *id;
const char *lastModifiedDateTime;
const char *name;
int size;
const char *webUrl;
int ratingRating;
int ratingSimpleRating;
const char *createdByUserDisplayName;
const char *createdByUserId;
const char *lastModifiedByUserDisplayName;
const char *lastModifiedByUserId;
const char *parentReferenceDriveId;
const char *parentReferenceDriveType;
const char *parentReferenceId;
const char *parentReferenceName;
const char *parentReferencePath;
const char *fileMimeType;
const char *fileHashesSha1Hash;
const char *fileSystemInfoCreatedDateTime;
const char *fileSystemInfoLastModifiedDateTime;
int imageHeight;
int imageWidth;
const char *photoTakenDateTime;
const char *sharedScope;
const char *sharedOwnerUserDisplayName;
const char *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 = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"client_id","2871da2c-8176-4b7f-869b-2311aa82e743");
CkJsonObject_UpdateString(json,"client_secret","2hu9Q~r5QuryUcEkNbg1btLtnfU1VUXzhSCG6brH");
CkJsonObject_UpdateString(json,"scope","https://graph.microsoft.com/.default");
CkJsonObject_UpdateString(json,"token_endpoint","https://login.microsoftonline.com/114d7ed6-71bf-4dbe-a866-748364121bf2/oauth2/v2.0/token");
http = CkHttp_Create();
CkHttp_putAuthToken(http,CkJsonObject_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
CkHttp_putFollowRedirects(http,TRUE);
// This example will get the metadata for /Misc/wildlife/penguins.jpg
CkHttp_SetUrlVar(http,"item_path","Misc//penguins.jpg");
CkHttp_SetUrlVar(http,"user_id","4fe732c3-322e-4a6b-b729-2fd1eb5c6104");
metaData = CkHttp_quickGetStr(http,"https://graph.microsoft.com/v1.0/users/{$user_id}/drive/root:/{$item_path}");
if (CkHttp_getLastMethodSuccess(http) != TRUE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkJsonObject_Dispose(json);
CkHttp_Dispose(http);
return;
}
CkJsonObject_putEmitCompact(json,FALSE);
success = CkJsonObject_Load(json,metaData);
printf("%s\n",CkJsonObject_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 (CkHttp_getLastStatus(http) != 200) {
printf("Response Status Code = %d\n",CkHttp_getLastStatus(http));
printf("Failed.\n");
CkJsonObject_Dispose(json);
CkHttp_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 = CkJsonObject_stringOf(json,"\"@odata.context\"");
microsoft_graph_downloadUrl = CkJsonObject_stringOf(json,"\"@microsoft.graph.downloadUrl\"");
createdDateTime = CkJsonObject_stringOf(json,"createdDateTime");
cTag = CkJsonObject_stringOf(json,"cTag");
eTag = CkJsonObject_stringOf(json,"eTag");
id = CkJsonObject_stringOf(json,"id");
lastModifiedDateTime = CkJsonObject_stringOf(json,"lastModifiedDateTime");
name = CkJsonObject_stringOf(json,"name");
size = CkJsonObject_IntOf(json,"size");
webUrl = CkJsonObject_stringOf(json,"webUrl");
ratingRating = CkJsonObject_IntOf(json,"rating.rating");
ratingSimpleRating = CkJsonObject_IntOf(json,"rating.simpleRating");
createdByUserDisplayName = CkJsonObject_stringOf(json,"createdBy.user.displayName");
createdByUserId = CkJsonObject_stringOf(json,"createdBy.user.id");
lastModifiedByUserDisplayName = CkJsonObject_stringOf(json,"lastModifiedBy.user.displayName");
lastModifiedByUserId = CkJsonObject_stringOf(json,"lastModifiedBy.user.id");
parentReferenceDriveId = CkJsonObject_stringOf(json,"parentReference.driveId");
parentReferenceDriveType = CkJsonObject_stringOf(json,"parentReference.driveType");
parentReferenceId = CkJsonObject_stringOf(json,"parentReference.id");
parentReferenceName = CkJsonObject_stringOf(json,"parentReference.name");
parentReferencePath = CkJsonObject_stringOf(json,"parentReference.path");
fileMimeType = CkJsonObject_stringOf(json,"file.mimeType");
fileHashesSha1Hash = CkJsonObject_stringOf(json,"file.hashes.sha1Hash");
fileSystemInfoCreatedDateTime = CkJsonObject_stringOf(json,"fileSystemInfo.createdDateTime");
fileSystemInfoLastModifiedDateTime = CkJsonObject_stringOf(json,"fileSystemInfo.lastModifiedDateTime");
imageHeight = CkJsonObject_IntOf(json,"image.height");
imageWidth = CkJsonObject_IntOf(json,"image.width");
photoTakenDateTime = CkJsonObject_stringOf(json,"photo.takenDateTime");
sharedScope = CkJsonObject_stringOf(json,"shared.scope");
sharedOwnerUserDisplayName = CkJsonObject_stringOf(json,"shared.owner.user.displayName");
sharedOwnerUserId = CkJsonObject_stringOf(json,"shared.owner.user.id");
CkJsonObject_Dispose(json);
CkHttp_Dispose(http);
}