Unicode C++ 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


#include <CkRestW.h>
#include <CkOAuth2W.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //   Provide a previously obtained OAuth2 access token.
    CkOAuth2W oauth2;
    oauth2.put_AccessToken(L"OAUTH2_ACCESS_TOKEN");
    rest.SetAuthOAuth2(oauth2);

    success = rest.Connect(L"www.googleapis.com",443,true,true);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    rest.AddQueryParam(L"includeTeamDriveItems",L"true");
    rest.AddQueryParam(L"supportsTeamDrives",L"true");

    CkStringBuilderW sbJson;
    success = rest.FullRequestNoBodySb(L"GET",L"/drive/v3/files/1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl/permissions",sbJson);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    if (rest.get_ResponseStatusCode() != 200) {
        wprintf(L"Received error response code: %d\n",rest.get_ResponseStatusCode());
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",sbJson.getAsString());
        return;
    }

    CkJsonObjectW json;
    json.LoadSb(sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.
    const wchar_t *kind = 0;
    int i;
    int count_i;
    const wchar_t *id = 0;
    const wchar_t *type = 0;
    const wchar_t *role = 0;
    bool allowFileDiscovery;

    kind = json.stringOf(L"kind");
    i = 0;
    count_i = json.SizeOfArray(L"permissions");
    while (i < count_i) {
        json.put_I(i);
        kind = json.stringOf(L"permissions[i].kind");
        id = json.stringOf(L"permissions[i].id");
        type = json.stringOf(L"permissions[i].type");
        role = json.stringOf(L"permissions[i].role");
        allowFileDiscovery = json.BoolOf(L"permissions[i].allowFileDiscovery");
        i = i + 1;
    }

    wprintf(L"Example Completed.\n");
    }

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"
    }
  ]
}