Retrieves a list of files for a particular team drive.
#include <C_CkRest.h>
#include <C_CkOAuth2.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkOAuth2 oauth2;
HCkStringBuilder sbJson;
HCkJsonObject json;
const char *kind;
BOOL incompleteSearch;
int i;
int count_i;
const char *id;
const char *name;
const char *mimeType;
const char *teamDriveId;
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,"teamDriveId","0AEd3EhGff2SaUk9PVA");
CkRest_AddQueryParam(rest,"includeTeamDriveItems","true");
CkRest_AddQueryParam(rest,"corpora","teamDrive");
CkRest_AddQueryParam(rest,"supportsTeamDrives","true");
sbJson = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"GET","/drive/v3/files",sbJson);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
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);
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");
incompleteSearch = CkJsonObject_BoolOf(json,"incompleteSearch");
i = 0;
count_i = CkJsonObject_SizeOfArray(json,"files");
while (i < count_i) {
CkJsonObject_putI(json,i);
kind = CkJsonObject_stringOf(json,"files[i].kind");
id = CkJsonObject_stringOf(json,"files[i].id");
name = CkJsonObject_stringOf(json,"files[i].name");
mimeType = CkJsonObject_stringOf(json,"files[i].mimeType");
teamDriveId = CkJsonObject_stringOf(json,"files[i].teamDriveId");
i = i + 1;
}
printf("Example Completed.\n");
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
}
{
"kind": "drive#fileList",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
"id": "18UpPSa-c_OPNi2CXY05gkpjIzNAJyd4q",
"name": "hedgehogs.jpg",
"mimeType": "image/jpeg",
"teamDriveId": "0AEd3EhGff2SaUk9PVA"
},
{
"kind": "drive#file",
"id": "1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl",
"name": "penguins.jpg",
"mimeType": "image/jpeg",
"teamDriveId": "0AEd3EhGff2SaUk9PVA"
},
{
"kind": "drive#file",
"id": "16MsxSRSz6ISRx1D_PXyA5Sj6aNFSEd4e",
"name": "seahorse.jpg",
"mimeType": "image/jpeg",
"teamDriveId": "0AEd3EhGff2SaUk9PVA"
},
{
"kind": "drive#file",
"id": "1lT4TbeSSMtxgB2MmwE7-5i7vQaxhr6Ze",
"name": "starfish2.jpg",
"mimeType": "image/jpeg",
"teamDriveId": "0AEd3EhGff2SaUk9PVA"
},
{
"kind": "drive#file",
"id": "1PVtx4SJB0n2GDcaJAbi_mSlQwXltYsx3",
"name": "test",
"mimeType": "application/vnd.google-apps.folder",
"teamDriveId": "0AEd3EhGff2SaUk9PVA"
}
]
}