Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Objective-C) Retrieve the metadata for a DriveItemSee more OneDrive ExamplesFetches 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
#import <CkoJsonObject.h> #import <CkoHttp.h> #import <NSString.h> // 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 CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json UpdateString: @"client_id" value: @"2871da2c-8176-4b7f-869b-2311aa82e743"]; [json UpdateString: @"client_secret" value: @"2hu9Q~r5QuryUcEkNbg1btLtnfU1VUXzhSCG6brH"]; [json UpdateString: @"scope" value: @"https://graph.microsoft.com/.default"]; [json UpdateString: @"token_endpoint" value: @"https://login.microsoftonline.com/114d7ed6-71bf-4dbe-a866-748364121bf2/oauth2/v2.0/token"]; CkoHttp *http = [[CkoHttp alloc] init]; http.AuthToken = [json Emit]; // 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 http.FollowRedirects = YES; // This example will get the metadata for /Misc/wildlife/penguins.jpg [http SetUrlVar: @"item_path" value: @"Misc//penguins.jpg"]; [http SetUrlVar: @"user_id" value: @"4fe732c3-322e-4a6b-b729-2fd1eb5c6104"]; NSString *metaData = [http QuickGetStr: @"https://graph.microsoft.com/v1.0/users/{$user_id}/drive/root:/{$item_path}"]; if (http.LastMethodSuccess != YES) { NSLog(@"%@",http.LastErrorText); return; } json.EmitCompact = NO; BOOL success = [json Load: metaData]; NSLog(@"%@",[json Emit]); // 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.LastStatus intValue] != 200) { NSLog(@"%@%d",@"Response Status Code = ",[http.LastStatus intValue]); NSLog(@"%@",@"Failed."); return; } // Demonstrate how to parse the JSON... NSString *odata_context = [json StringOf: @"\"@odata.context\""]; NSString *microsoft_graph_downloadUrl = [json StringOf: @"\"@microsoft.graph.downloadUrl\""]; NSString *createdDateTime = [json StringOf: @"createdDateTime"]; NSString *cTag = [json StringOf: @"cTag"]; NSString *eTag = [json StringOf: @"eTag"]; NSString *id = [json StringOf: @"id"]; NSString *lastModifiedDateTime = [json StringOf: @"lastModifiedDateTime"]; NSString *name = [json StringOf: @"name"]; int size = [[json IntOf: @"size"] intValue]; NSString *webUrl = [json StringOf: @"webUrl"]; int ratingRating = [[json IntOf: @"rating.rating"] intValue]; int ratingSimpleRating = [[json IntOf: @"rating.simpleRating"] intValue]; NSString *createdByUserDisplayName = [json StringOf: @"createdBy.user.displayName"]; NSString *createdByUserId = [json StringOf: @"createdBy.user.id"]; NSString *lastModifiedByUserDisplayName = [json StringOf: @"lastModifiedBy.user.displayName"]; NSString *lastModifiedByUserId = [json StringOf: @"lastModifiedBy.user.id"]; NSString *parentReferenceDriveId = [json StringOf: @"parentReference.driveId"]; NSString *parentReferenceDriveType = [json StringOf: @"parentReference.driveType"]; NSString *parentReferenceId = [json StringOf: @"parentReference.id"]; NSString *parentReferenceName = [json StringOf: @"parentReference.name"]; NSString *parentReferencePath = [json StringOf: @"parentReference.path"]; NSString *fileMimeType = [json StringOf: @"file.mimeType"]; NSString *fileHashesSha1Hash = [json StringOf: @"file.hashes.sha1Hash"]; NSString *fileSystemInfoCreatedDateTime = [json StringOf: @"fileSystemInfo.createdDateTime"]; NSString *fileSystemInfoLastModifiedDateTime = [json StringOf: @"fileSystemInfo.lastModifiedDateTime"]; int imageHeight = [[json IntOf: @"image.height"] intValue]; int imageWidth = [[json IntOf: @"image.width"] intValue]; NSString *photoTakenDateTime = [json StringOf: @"photo.takenDateTime"]; NSString *sharedScope = [json StringOf: @"shared.scope"]; NSString *sharedOwnerUserDisplayName = [json StringOf: @"shared.owner.user.displayName"]; NSString *sharedOwnerUserId = [json StringOf: @"shared.owner.user.id"]; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.