PowerBuilder Google Drive: List Changes to a TeamDrive

Back to Index

Download a list of changes to a teamdrive. This example lists the changes for the team drive having id = "0AEd3EhGff2SaUk9PVA". The "pageToken" is obtained from a previous call to /drive/v3/changes/startPageToken or from the "nextPageToken" member of the previous call to list changes.

Documentation: https://developers.google.com/drive/v3/reference/changes/list


integer li_rc
oleobject loo_Rest
integer li_Success
oleobject loo_Oauth2
oleobject loo_SbJson
oleobject loo_Json
string ls_Kind
string ls_NewStartPageToken
integer i
integer li_Count_i
string ls_Type
string ls_Time
integer li_Removed
string ls_FileId
string ls_FileKind
string ls_FileName
string ls_FileMimeType
string ls_FileTeamDriveId

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//   Provide a previously obtained OAuth2 access token.
loo_Oauth2 = create oleobject
li_rc = loo_Oauth2.ConnectToNewObject("Chilkat_9_5_0.OAuth2")

loo_Oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loo_Rest.SetAuthOAuth2(loo_Oauth2)

li_Success = loo_Rest.Connect("www.googleapis.com",443,1,1)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    return
end if

loo_Rest.AddQueryParam("teamDriveId","0AEd3EhGff2SaUk9PVA")
loo_Rest.AddQueryParam("pageToken","13")
loo_Rest.AddQueryParam("includeTeamDriveItems","true")
loo_Rest.AddQueryParam("supportsTeamDrives","true")

loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/drive/v3/changes",loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_SbJson
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Response body:"
    Write-Debug loo_SbJson.GetAsString()
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_SbJson
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.LoadSb(loo_SbJson)

//  The following code parses the JSON response.
//  A sample JSON response is shown below the sample code.

ls_Kind = loo_Json.StringOf("kind")
ls_NewStartPageToken = loo_Json.StringOf("newStartPageToken")
i = 0
li_Count_i = loo_Json.SizeOfArray("changes")
do while i < li_Count_i
    loo_Json.I = i
    ls_Kind = loo_Json.StringOf("changes[i].kind")
    ls_Type = loo_Json.StringOf("changes[i].type")
    ls_Time = loo_Json.StringOf("changes[i].time")
    li_Removed = loo_Json.BoolOf("changes[i].removed")
    ls_FileId = loo_Json.StringOf("changes[i].fileId")
    ls_FileKind = loo_Json.StringOf("changes[i].file.kind")
    ls_FileId = loo_Json.StringOf("changes[i].file.id")
    ls_FileName = loo_Json.StringOf("changes[i].file.name")
    ls_FileMimeType = loo_Json.StringOf("changes[i].file.mimeType")
    ls_FileTeamDriveId = loo_Json.StringOf("changes[i].file.teamDriveId")
    i = i + 1
loop

Write-Debug "Example Completed."


destroy loo_Rest
destroy loo_Oauth2
destroy loo_SbJson
destroy loo_Json

Sample JSON Response Body

{
  "kind": "drive#changeList",
  "newStartPageToken": "16",
  "changes": [
    {
      "kind": "drive#change",
      "type": "file",
      "time": "2017-11-13T17:04:47.470Z",
      "removed": false,
      "fileId": "1lT4TbeSSMtxgB2MmwE7-5i7vQaxhr6Ze",
      "file": {
        "kind": "drive#file",
        "id": "1lT4TbeSSMtxgB2MmwE7-5i7vQaxhr6Ze",
        "name": "starfish2.jpg",
        "mimeType": "image/jpeg",
        "teamDriveId": "0AEd3EhGff2SaUk9PVA"
      }
    },
    {
      "kind": "drive#change",
      "type": "file",
      "time": "2017-11-13T17:05:01.095Z",
      "removed": false,
      "fileId": "16MsxSRSz6ISRx1D_PXyA5Sj6aNFSEd4e",
      "file": {
        "kind": "drive#file",
        "id": "16MsxSRSz6ISRx1D_PXyA5Sj6aNFSEd4e",
        "name": "seahorse.jpg",
        "mimeType": "image/jpeg",
        "teamDriveId": "0AEd3EhGff2SaUk9PVA"
      }
    }
  ]
}