/// <summary> /// This function is used to create a new instance of Drive client service /// </summary> /// <returns></returns> public async Task <DriveService> CreateDriveClientAsync() { var driveAuth = _googleCloudConfig.DriveAuth; var credPath = Path.Combine("Storage", "Common", "gdrive-auth-token-store").SanitizeSlash().EnsureDirectory(); var secrets = await GoogleClientSecrets.FromFileAsync(driveAuth); var fileDataStore = new FileDataStore(credPath, true); var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( secrets.Secrets, new[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile }, "user", CancellationToken.None, fileDataStore); Log.Debug("Credential saved to {CredPath}", credPath); Log.Debug("Initializing Drive service"); var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "ZiziBot" }); return(service); }
private static async Task GrabGoogleDocsAnswers() { string[] scopes = { DocsService.Scope.DocumentsReadonly }; string ApplicationName = "Google Docs API .NET Quickstart"; var secretsFile = "client_secret.apps.googleusercontent.com.json"; string credPath = "token.json"; UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( (await GoogleClientSecrets.FromFileAsync(secretsFile)).Secrets, scopes, "user", CancellationToken.None, new FileDataStore(credPath, true) ); Console.WriteLine("Credential file saved to: " + credPath); /* Create Google Docs API service. */ var service = new DocsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); const string documentId = "1bfifCfwhLuhP-_dXvtQdgByGpcvvWIgDrRQbeQrExtg"; DocumentsResource.GetRequest request = service.Documents.Get(documentId); Document doc = await request.ExecuteAsync(); int counter = 0; while (counter < doc.Body.Content.Count) { if (doc.Body.Content[counter]?.Paragraph?.Bullet != null) { string a = string.Join("", doc.Body.Content[counter + 1].Paragraph.Elements.Select(e => e.TextRun.Content)); a = a.Replace("Answer: ", ""); QaDict.Add(new List <string> { ProcessString(doc.Body.Content[counter].Paragraph.Elements[0].TextRun.Content), ProcessString(a) }); counter++; } counter++; } }