Creates a new permission for a file. (In this example the permission is created for the file with id = 1BXNQ4sMDD1WibOtcYqgQlwJa0MAa6rTQ)
#include <C_CkRest.h>
#include <C_CkOAuth2.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkOAuth2 oauth2;
HCkJsonObject jsonReq;
HCkStringBuilder sbReq;
HCkStringBuilder sbJson;
HCkJsonObject json;
const char *kind;
const char *id;
const char *type;
const char *role;
BOOL allowFileDiscovery;
rest = CkRest_Create();
// Provide a previously obtained OAuth2 access token.
oauth2 = CkOAuth2_Create();
CkOAuth2_putAccessToken(oauth2,"OAUTH2_ACCESS_TOKEN");
CkRest_SetAuthOAuth2(rest,oauth2);
success = CkRest_Connect(rest,"www.googleapis.com",443,TRUE,TRUE);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
return;
}
CkRest_AddQueryParam(rest,"includeTeamDriveItems","true");
CkRest_AddQueryParam(rest,"supportsTeamDrives","true");
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
jsonReq = CkJsonObject_Create();
CkJsonObject_UpdateString(jsonReq,"role","reader");
CkJsonObject_UpdateString(jsonReq,"type","anyone");
sbReq = CkStringBuilder_Create();
CkJsonObject_EmitSb(jsonReq,sbReq);
CkRest_AddHeader(rest,"Content-Type","application/json");
sbJson = CkStringBuilder_Create();
success = CkRest_FullRequestSb(rest,"POST","/drive/v3/files/1BXNQ4sMDD1WibOtcYqgQlwJa0MAa6rTQ/permissions",sbReq,sbJson);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkJsonObject_Dispose(jsonReq);
CkStringBuilder_Dispose(sbReq);
CkStringBuilder_Dispose(sbJson);
return;
}
if (CkRest_getResponseStatusCode(rest) != 200) {
printf("Received error response code: %d\n",CkRest_getResponseStatusCode(rest));
printf("Response body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbJson));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkJsonObject_Dispose(jsonReq);
CkStringBuilder_Dispose(sbReq);
CkStringBuilder_Dispose(sbJson);
return;
}
json = CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
kind = CkJsonObject_stringOf(json,"kind");
id = CkJsonObject_stringOf(json,"id");
type = CkJsonObject_stringOf(json,"type");
role = CkJsonObject_stringOf(json,"role");
allowFileDiscovery = CkJsonObject_BoolOf(json,"allowFileDiscovery");
printf("Example Completed.\n");
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkJsonObject_Dispose(jsonReq);
CkStringBuilder_Dispose(sbReq);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
}
{
"role": "reader",
"type": "anyone"
}
{
"kind": "drive#permission",
"id": "anyoneWithLink",
"type": "anyone",
"role": "reader",
"allowFileDiscovery": false
}