Visual FoxPro Google Drive: List Files on a Team Drive

Back to Index

Retrieves a list of files for a particular team drive.

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


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loSbJson
LOCAL loJson
LOCAL lcKind
LOCAL lnIncompleteSearch
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lcName
LOCAL lcMimeType
LOCAL lcTeamDriveId

loRest = CreateObject('Chilkat_9_5_0.Rest')

*   Provide a previously obtained OAuth2 access token.
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loRest.SetAuthOAuth2(loOauth2)

lnSuccess = loRest.Connect("www.googleapis.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    CANCEL
ENDIF

loRest.AddQueryParam("teamDriveId","0AEd3EhGff2SaUk9PVA")
loRest.AddQueryParam("includeTeamDriveItems","true")
loRest.AddQueryParam("corpora","teamDrive")
loRest.AddQueryParam("supportsTeamDrives","true")

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/drive/v3/files",loSbJson)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbJson
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Received error response code: " + STR(loRest.ResponseStatusCode)
    ? "Response body:"
    ? loSbJson.GetAsString()
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbJson
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.LoadSb(loSbJson)

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

lcKind = loJson.StringOf("kind")
lnIncompleteSearch = loJson.BoolOf("incompleteSearch")
i = 0
lnCount_i = loJson.SizeOfArray("files")
DO WHILE i < lnCount_i
    loJson.I = i
    lcKind = loJson.StringOf("files[i].kind")
    lcId = loJson.StringOf("files[i].id")
    lcName = loJson.StringOf("files[i].name")
    lcMimeType = loJson.StringOf("files[i].mimeType")
    lcTeamDriveId = loJson.StringOf("files[i].teamDriveId")
    i = i + 1
ENDDO

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loSbJson
RELEASE loJson

Sample JSON Response Body

{
  "kind": "drive#fileList",
  "incompleteSearch": false,
  "files": [
    {
      "kind": "drive#file",
      "id": "18UpPSa-c_OPNi2CXY05gkpjIzNAJyd4q",
      "name": "hedgehogs.jpg",
      "mimeType": "image/jpeg",
      "teamDriveId": "0AEd3EhGff2SaUk9PVA"
    },
    {
      "kind": "drive#file",
      "id": "1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl",
      "name": "penguins.jpg",
      "mimeType": "image/jpeg",
      "teamDriveId": "0AEd3EhGff2SaUk9PVA"
    },
    {
      "kind": "drive#file",
      "id": "16MsxSRSz6ISRx1D_PXyA5Sj6aNFSEd4e",
      "name": "seahorse.jpg",
      "mimeType": "image/jpeg",
      "teamDriveId": "0AEd3EhGff2SaUk9PVA"
    },
    {
      "kind": "drive#file",
      "id": "1lT4TbeSSMtxgB2MmwE7-5i7vQaxhr6Ze",
      "name": "starfish2.jpg",
      "mimeType": "image/jpeg",
      "teamDriveId": "0AEd3EhGff2SaUk9PVA"
    },
    {
      "kind": "drive#file",
      "id": "1PVtx4SJB0n2GDcaJAbi_mSlQwXltYsx3",
      "name": "test",
      "mimeType": "application/vnd.google-apps.folder",
      "teamDriveId": "0AEd3EhGff2SaUk9PVA"
    }
  ]
}