List the permissions for a file by file id. (In this example the file id = 1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl)
#include <C_CkRestW.h>
#include <C_CkOAuth2W.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
HCkOAuth2W oauth2;
HCkStringBuilderW sbJson;
HCkJsonObjectW json;
const wchar_t *kind;
int i;
int count_i;
const wchar_t *id;
const wchar_t *type;
const wchar_t *role;
BOOL allowFileDiscovery;
rest = CkRestW_Create();
// Provide a previously obtained OAuth2 access token.
oauth2 = CkOAuth2W_Create();
CkOAuth2W_putAccessToken(oauth2,L"OAUTH2_ACCESS_TOKEN");
CkRestW_SetAuthOAuth2(rest,oauth2);
success = CkRestW_Connect(rest,L"www.googleapis.com",443,TRUE,TRUE);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkOAuth2W_Dispose(oauth2);
return;
}
CkRestW_AddQueryParam(rest,L"includeTeamDriveItems",L"true");
CkRestW_AddQueryParam(rest,L"supportsTeamDrives",L"true");
sbJson = CkStringBuilderW_Create();
success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/drive/v3/files/1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl/permissions",sbJson);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkOAuth2W_Dispose(oauth2);
CkStringBuilderW_Dispose(sbJson);
return;
}
if (CkRestW_getResponseStatusCode(rest) != 200) {
wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
wprintf(L"Response body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
CkRestW_Dispose(rest);
CkOAuth2W_Dispose(oauth2);
CkStringBuilderW_Dispose(sbJson);
return;
}
json = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(json,sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
kind = CkJsonObjectW_stringOf(json,L"kind");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"permissions");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
kind = CkJsonObjectW_stringOf(json,L"permissions[i].kind");
id = CkJsonObjectW_stringOf(json,L"permissions[i].id");
type = CkJsonObjectW_stringOf(json,L"permissions[i].type");
role = CkJsonObjectW_stringOf(json,L"permissions[i].role");
allowFileDiscovery = CkJsonObjectW_BoolOf(json,L"permissions[i].allowFileDiscovery");
i = i + 1;
}
wprintf(L"Example Completed.\n");
CkRestW_Dispose(rest);
CkOAuth2W_Dispose(oauth2);
CkStringBuilderW_Dispose(sbJson);
CkJsonObjectW_Dispose(json);
}
{
"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"
}
]
}