Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Retrieve the metadata for a DriveItemFetches the JSON metadata for a DriveItem. For more information, see https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online
#include <CkHttp.h> #include <CkJsonObject.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; // Use your previously obtained access token here: // See the following examples for getting an access token: // Get Microsoft Graph OAuth2 Access Token (Azure AD v2.0 Endpoint). // Get Microsoft Graph OAuth2 Access Token (Azure AD Endpoint). // Refresh Access Token (Azure AD v2.0 Endpoint). // Refresh Access Token (Azure AD Endpoint). // (Make sure your token was obtained with the FilesRead or Files.ReadWrite scope.) http.put_AuthToken("MICROSOFT_GRAPH_ACCESS_TOKEN"); // Sends the following GET request: // GET https://graph.microsoft.com/v1.0/me/drive/root:/{item-path} // Make sure to automatically follow redirects http.put_FollowRedirects(true); // This example will get the metadata for /Misc/wildlife/penguins.jpg http.SetUrlVar("item_path","Misc/wildlife/penguins.jpg"); const char *metaData = http.quickGetStr("https://graph.microsoft.com/v1.0/me/drive/root:/{$item_path}"); if (http.get_LastMethodSuccess() != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkJsonObject json; json.put_EmitCompact(false); bool success = json.Load(metaData); strOut.append(json.emit()); strOut.append("\r\n"); // 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 (http.get_LastStatus() != 200) { strOut.append("Response Status Code = "); strOut.appendInt(http.get_LastStatus()); strOut.append("\r\n"); strOut.append("Failed."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); 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. const char *odata_context = json.stringOf("\"@odata.context\""); const char *microsoft_graph_downloadUrl = json.stringOf("\"@microsoft.graph.downloadUrl\""); const char *createdDateTime = json.stringOf("createdDateTime"); const char *cTag = json.stringOf("cTag"); const char *eTag = json.stringOf("eTag"); const char *id = json.stringOf("id"); const char *lastModifiedDateTime = json.stringOf("lastModifiedDateTime"); const char *name = json.stringOf("name"); int size = json.IntOf("size"); const char *webUrl = json.stringOf("webUrl"); int ratingRating = json.IntOf("rating.rating"); int ratingSimpleRating = json.IntOf("rating.simpleRating"); const char *createdByUserDisplayName = json.stringOf("createdBy.user.displayName"); const char *createdByUserId = json.stringOf("createdBy.user.id"); const char *lastModifiedByUserDisplayName = json.stringOf("lastModifiedBy.user.displayName"); const char *lastModifiedByUserId = json.stringOf("lastModifiedBy.user.id"); const char *parentReferenceDriveId = json.stringOf("parentReference.driveId"); const char *parentReferenceDriveType = json.stringOf("parentReference.driveType"); const char *parentReferenceId = json.stringOf("parentReference.id"); const char *parentReferenceName = json.stringOf("parentReference.name"); const char *parentReferencePath = json.stringOf("parentReference.path"); const char *fileMimeType = json.stringOf("file.mimeType"); const char *fileHashesSha1Hash = json.stringOf("file.hashes.sha1Hash"); const char *fileSystemInfoCreatedDateTime = json.stringOf("fileSystemInfo.createdDateTime"); const char *fileSystemInfoLastModifiedDateTime = json.stringOf("fileSystemInfo.lastModifiedDateTime"); int imageHeight = json.IntOf("image.height"); int imageWidth = json.IntOf("image.width"); const char *photoTakenDateTime = json.stringOf("photo.takenDateTime"); const char *sharedScope = json.stringOf("shared.scope"); const char *sharedOwnerUserDisplayName = json.stringOf("shared.owner.user.displayName"); const char *sharedOwnerUserId = json.stringOf("shared.owner.user.id"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.