# Track Google Drive Changes

Read Google Drive change feeds for the user and shared drives with checkpoints, and apply sync plans with dry runs, approvals, and conflict reporting.

**Packages**

- [OfficeIMO.GoogleWorkspace.Sync](https://www.nuget.org/packages/OfficeIMO.GoogleWorkspace.Sync) `dotnet add package OfficeIMO.GoogleWorkspace.Sync`
- [OfficeIMO.GoogleWorkspace](https://www.nuget.org/packages/OfficeIMO.GoogleWorkspace) `dotnet add package OfficeIMO.GoogleWorkspace`

**Works with**

- .NET

**Target frameworks**

netstandard2.0, net8.0, net10.0, net472

**APIs**

- [`GoogleWorkspaceChangeTracker`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacechangetracker/)
- [`GoogleWorkspaceSyncApplyOptions`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacesyncapplyoptions/)
- [`GoogleWorkspaceSyncExecutor`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacesyncexecutor/)
- [`GoogleWorkspaceSyncItem`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacesyncitem/)
- [`GoogleServiceAccountCredentialSource`](/api/google-workspace/officeimo-googleworkspace-googleserviceaccountcredentialsource/)
- [`GoogleWorkspaceChangeReadOptions`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacechangereadoptions/)
- [`GoogleWorkspaceChangeReadResult`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacechangereadresult/)
- [`GoogleWorkspaceSession`](/api/google-workspace/officeimo-googleworkspace-googleworkspacesession/)
- [`GoogleWorkspaceSyncCheckpoint`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacesynccheckpoint/)
- [`GoogleWorkspaceTrackedChange`](/api/google-workspace-sync/officeimo-googleworkspace-sync-googleworkspacetrackedchange/)

**Data**

- [OfficeIMO.GoogleWorkspace.Sync API index](/api/google-workspace-sync/index.json)
- [OfficeIMO.GoogleWorkspace API index](/api/google-workspace/index.json)

`GoogleWorkspaceChangeTracker` in `OfficeIMO.GoogleWorkspace.Sync` reads the user change feed and any shared-drive feeds you name. Initialize the cursors once, store the checkpoint, and read complete pages on later runs. The checkpoint holds cursors and optional identity and revision data, never document content. Your application owns checkpoint storage, schedules, approval UI, and conflict decisions.

## Read changes since the last run

Move to `read.NextCheckpoint` only after you have processed the returned changes. Each source cursor moves only when that source reached its new start token, so one failing shared drive does not advance another.

### C#

```csharp
using OfficeIMO.GoogleWorkspace;
using OfficeIMO.GoogleWorkspace.Sync;

using var credentials = GoogleServiceAccountCredentialSource.FromFile("service-account.json");
var session = new GoogleWorkspaceSession(credentials);

using var tracker = new GoogleWorkspaceChangeTracker(session);
GoogleWorkspaceSyncCheckpoint checkpoint = await tracker.InitializeAsync(new[] { "shared-drive-id" });

var readOptions = new GoogleWorkspaceChangeReadOptions();
readOptions.SharedDriveIds.Add("shared-drive-id");

GoogleWorkspaceChangeReadResult read = await tracker.ReadAsync(checkpoint, readOptions);
foreach (GoogleWorkspaceTrackedChange tracked in read.Changes) {
    Console.WriteLine($"{tracked.Source.Kind} {tracked.Change.FileId} removed={tracked.Change.Removed}");
}

checkpoint = read.NextCheckpoint;
```

## Apply a sync plan

Turn a Docs, Sheets, or Slides diff into `GoogleWorkspaceSyncItem` values and run them through `GoogleWorkspaceSyncExecutor`. It is a dry run by default (`DryRun = true` in `GoogleWorkspaceSyncApplyOptions`), never calls your mutation callback for a conflict, and requires approval by stable ID (`ApprovedLossyItemIds`) for lossy items. Set `DryRun = false` to apply. The result reports each item as planned, applied, skipped, conflict, approval-required, failed, or canceled, and can return the progress already made when the run is canceled.

<!-- PowerForge markdown source sha256:7822ADF4FC9C2838E031C01167F7A78E9C217C844DE0D0902DDD646BA9E1FAFF; title=True -->

<!-- PowerForge markdown artifact sha256:E289CB3F8DA15A0E299F72D72036D3957078AE2EB78E9A8180FBE8A8BE85CD49 -->
