Skip to content

Files

Latest commit

 

History

History
33 lines (26 loc) · 1.14 KB

File metadata and controls

33 lines (26 loc) · 1.14 KB

SharpGrip FileSystem GoogleDrive adapter NuGet

Installation

Reference NuGet package SharpGrip.FileSystem.Adapters.GoogleDrive (https://www.nuget.org/packages/SharpGrip.FileSystem.Adapters.GoogleDrive).

Usage

// Google connection.
await using var stream = new FileStream("path/to/credentials.json", FileMode.Open, FileAccess.Read);
const string tokenPath = "path/to/token/directory";
var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    (await GoogleClientSecrets.FromStreamAsync(stream)).Secrets,
    new[] {DriveService.Scope.Drive},
    "user",
    CancellationToken.None,
    new FileDataStore(tokenPath, true));

var googleDriveClient = new DriveService(new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = "Test"
});

var adapters = new List<IAdapter>
{
    new LocalAdapter("local", "/var/files"),
    new GoogleDriveAdapter("google-drive", "/Files", googleDriveClient)
};

var fileSystem = new FileSystem(adapters);