Visual FoxPro Google Drive: List a File's Permissions

Back to Index

List the permissions for a file by file id. (In this example the file id = 1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl)

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


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loSbJson
LOCAL loJson
LOCAL lcKind
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lcType
LOCAL lcRole
LOCAL lnAllowFileDiscovery

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("includeTeamDriveItems","true")
loRest.AddQueryParam("supportsTeamDrives","true")

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/drive/v3/files/1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl/permissions",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("permissions")
DO WHILE i < lnCount_i
    loJson.I = i
    lcKind = loJson.StringOf("permissions[i].kind")
    lcId = loJson.StringOf("permissions[i].id")
    lcType = loJson.StringOf("permissions[i].type")
    lcRole = loJson.StringOf("permissions[i].role")
    lnAllowFileDiscovery = loJson.BoolOf("permissions[i].allowFileDiscovery")
    i = i + 1
ENDDO

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loSbJson
RELEASE loJson

Sample JSON Response Body

{
  "kind": "drive#permissionList",
  "permissions": [
    {
      "kind": "drive#permission",
      "id": "07604395918166943595k",
      "type": "domain",
      "role": "reader",
      "allowFileDiscovery": false
    },
    {
      "kind": "drive#permission",
      "id": "05909037819814716957",
      "type": "user",
      "role": "organizer"
    },
    {
      "kind": "drive#permission",
      "id": "13254573739200948291",
      "type": "user",
      "role": "organizer"
    }
  ]
}