C Google Drive: List Changes to a TeamDrive

Back to Index

Download a list of changes to a teamdrive. This example lists the changes for the team drive having id = "0AEd3EhGff2SaUk9PVA". The "pageToken" is obtained from a previous call to /drive/v3/changes/startPageToken or from the "nextPageToken" member of the previous call to list changes.

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


#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;
    const char *newStartPageToken;
    int i;
    int count_i;
    const char *type;
    const char *time;
    BOOL removed;
    const char *fileId;
    const char *fileKind;
    const char *fileName;
    const char *fileMimeType;
    const char *fileTeamDriveId;

    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,"pageToken","13");
    CkRest_AddQueryParam(rest,"includeTeamDriveItems","true");
    CkRest_AddQueryParam(rest,"supportsTeamDrives","true");

    sbJson = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/drive/v3/changes",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");
    newStartPageToken = CkJsonObject_stringOf(json,"newStartPageToken");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"changes");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        kind = CkJsonObject_stringOf(json,"changes[i].kind");
        type = CkJsonObject_stringOf(json,"changes[i].type");
        time = CkJsonObject_stringOf(json,"changes[i].time");
        removed = CkJsonObject_BoolOf(json,"changes[i].removed");
        fileId = CkJsonObject_stringOf(json,"changes[i].fileId");
        fileKind = CkJsonObject_stringOf(json,"changes[i].file.kind");
        fileId = CkJsonObject_stringOf(json,"changes[i].file.id");
        fileName = CkJsonObject_stringOf(json,"changes[i].file.name");
        fileMimeType = CkJsonObject_stringOf(json,"changes[i].file.mimeType");
        fileTeamDriveId = CkJsonObject_stringOf(json,"changes[i].file.teamDriveId");
        i = i + 1;
    }

    printf("Example Completed.\n");


    CkRest_Dispose(rest);
    CkOAuth2_Dispose(oauth2);
    CkStringBuilder_Dispose(sbJson);
    CkJsonObject_Dispose(json);

    }

Sample JSON Response Body

{
  "kind": "drive#changeList",
  "newStartPageToken": "16",
  "changes": [
    {
      "kind": "drive#change",
      "type": "file",
      "time": "2017-11-13T17:04:47.470Z",
      "removed": false,
      "fileId": "1lT4TbeSSMtxgB2MmwE7-5i7vQaxhr6Ze",
      "file": {
        "kind": "drive#file",
        "id": "1lT4TbeSSMtxgB2MmwE7-5i7vQaxhr6Ze",
        "name": "starfish2.jpg",
        "mimeType": "image/jpeg",
        "teamDriveId": "0AEd3EhGff2SaUk9PVA"
      }
    },
    {
      "kind": "drive#change",
      "type": "file",
      "time": "2017-11-13T17:05:01.095Z",
      "removed": false,
      "fileId": "16MsxSRSz6ISRx1D_PXyA5Sj6aNFSEd4e",
      "file": {
        "kind": "drive#file",
        "id": "16MsxSRSz6ISRx1D_PXyA5Sj6aNFSEd4e",
        "name": "seahorse.jpg",
        "mimeType": "image/jpeg",
        "teamDriveId": "0AEd3EhGff2SaUk9PVA"
      }
    }
  ]
}