Visual FoxPro Google Drive: List Team Drives

Back to Index

Lists the user's Team Drives.

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


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loSbJson
LOCAL loJson
LOCAL lcKind
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lcName

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

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/drive/v3/teamdrives",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")
i = 0
lnCount_i = loJson.SizeOfArray("teamDrives")
DO WHILE i < lnCount_i
    loJson.I = i
    lcKind = loJson.StringOf("teamDrives[i].kind")
    lcId = loJson.StringOf("teamDrives[i].id")
    lcName = loJson.StringOf("teamDrives[i].name")
    i = i + 1
ENDDO

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loSbJson
RELEASE loJson

Sample JSON Response Body

{
  "kind": "drive#teamDriveList",
  "teamDrives": [
    {
      "kind": "drive#teamDrive",
      "id": "0AEd3EhGff2SaUk9PVA",
      "name": "Project Pegasus"
    },
    {
      "kind": "drive#teamDrive",
      "id": "0AGO-j6qTGkqgUk9PVA",
      "name": "Project Unicorn"
    }
  ]
}