Sample code for 30+ languages & platforms
Xbase++

Retrieve the metadata for a DriveItem

See more OneDrive Examples

Fetches the JSON metadata for a DriveItem.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJson
LOCAL oHttp
LOCAL cMetaData
LOCAL cOdata_context
LOCAL cMicrosoft_graph_downloadUrl
LOCAL cCreatedDateTime
LOCAL cCTag
LOCAL cETag
LOCAL cId
LOCAL cLastModifiedDateTime
LOCAL cName
LOCAL nSize
LOCAL cWebUrl
LOCAL nRatingRating
LOCAL nRatingSimpleRating
LOCAL cCreatedByUserDisplayName
LOCAL cCreatedByUserId
LOCAL cLastModifiedByUserDisplayName
LOCAL cLastModifiedByUserId
LOCAL cParentReferenceDriveId
LOCAL cParentReferenceDriveType
LOCAL cParentReferenceId
LOCAL cParentReferenceName
LOCAL cParentReferencePath
LOCAL cFileMimeType
LOCAL cFileHashesSha1Hash
LOCAL cFileSystemInfoCreatedDateTime
LOCAL cFileSystemInfoLastModifiedDateTime
LOCAL nImageHeight
LOCAL nImageWidth
LOCAL cPhotoTakenDateTime
LOCAL cSharedScope
LOCAL cSharedOwnerUserDisplayName
LOCAL cSharedOwnerUserId

nSuccess := 0

//  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
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("client_id", "2871da2c-8176-4b7f-869b-2311aa82e743")
oJson:UpdateString("client_secret", "2hu9Q~r5QuryUcEkNbg1btLtnfU1VUXzhSCG6brH")
oJson:UpdateString("scope", "https://graph.microsoft.com/.default")
oJson:UpdateString("token_endpoint", "https://login.microsoftonline.com/114d7ed6-71bf-4dbe-a866-748364121bf2/oauth2/v2.0/token")

oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := oJson: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
oHttp:FollowRedirects := 1

//  This example will get the metadata for /Misc/wildlife/penguins.jpg
oHttp:SetUrlVar("item_path", "Misc//penguins.jpg")
oHttp:SetUrlVar("user_id", "4fe732c3-322e-4a6b-b729-2fd1eb5c6104")

cMetaData := oHttp:QuickGetStr("https://graph.microsoft.com/v1.0/users/{$user_id}/drive/root:/{$item_path}")
IF (oHttp:LastMethodSuccess != 1)
    ? oHttp:LastErrorText
    oJson:destroy()
    oHttp:destroy()
    RETURN
ENDIF

oJson:EmitCompact := 0
nSuccess := oJson:Load(cMetaData)
? oJson: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 (oHttp:LastStatus != 200)
    ? "Response Status Code = " + Str(oHttp:LastStatus)
    ? "Failed."
    oJson:destroy()
    oHttp:destroy()
    RETURN
ENDIF

//  Demonstrate how to parse the JSON...

cOdata_context := oJson:StringOf('"@odata.context"')
cMicrosoft_graph_downloadUrl := oJson:StringOf('"@microsoft.graph.downloadUrl"')
cCreatedDateTime := oJson:StringOf("createdDateTime")
cCTag := oJson:StringOf("cTag")
cETag := oJson:StringOf("eTag")
cId := oJson:StringOf("id")
cLastModifiedDateTime := oJson:StringOf("lastModifiedDateTime")
cName := oJson:StringOf("name")
nSize := oJson:IntOf("size")
cWebUrl := oJson:StringOf("webUrl")
nRatingRating := oJson:IntOf("rating.rating")
nRatingSimpleRating := oJson:IntOf("rating.simpleRating")
cCreatedByUserDisplayName := oJson:StringOf("createdBy.user.displayName")
cCreatedByUserId := oJson:StringOf("createdBy.user.id")
cLastModifiedByUserDisplayName := oJson:StringOf("lastModifiedBy.user.displayName")
cLastModifiedByUserId := oJson:StringOf("lastModifiedBy.user.id")
cParentReferenceDriveId := oJson:StringOf("parentReference.driveId")
cParentReferenceDriveType := oJson:StringOf("parentReference.driveType")
cParentReferenceId := oJson:StringOf("parentReference.id")
cParentReferenceName := oJson:StringOf("parentReference.name")
cParentReferencePath := oJson:StringOf("parentReference.path")
cFileMimeType := oJson:StringOf("file.mimeType")
cFileHashesSha1Hash := oJson:StringOf("file.hashes.sha1Hash")
cFileSystemInfoCreatedDateTime := oJson:StringOf("fileSystemInfo.createdDateTime")
cFileSystemInfoLastModifiedDateTime := oJson:StringOf("fileSystemInfo.lastModifiedDateTime")
nImageHeight := oJson:IntOf("image.height")
nImageWidth := oJson:IntOf("image.width")
cPhotoTakenDateTime := oJson:StringOf("photo.takenDateTime")
cSharedScope := oJson:StringOf("shared.scope")
cSharedOwnerUserDisplayName := oJson:StringOf("shared.owner.user.displayName")
cSharedOwnerUserId := oJson:StringOf("shared.owner.user.id")

oJson:destroy()
oHttp:destroy()