заменить текст в Google Docs, используя ядро ​​c # .net - PullRequest
0 голосов
/ 17 апреля 2019

Я пытаюсь найти и заменить текст в моих Документах Google, используя c # .Net Core. Мне удалось подключиться к API с помощью начального набора Google и отобразить заголовок документа. Я пытался просмотреть Документы Google, но, похоже, ничего не понял. Ниже приведен код, который у меня есть.

    static string[] Scopes = { DocsService.Scope.DocumentsReadonly };
    static string ApplicationName = "Google Docs API .NET Quickstart";

    public IActionResult Index()
    {

        {
            // If modifying these scopes, delete your previously saved credentials
            // at ~/.credentials/docs.googleapis.com-dotnet-quickstart.json



            {
                UserCredential credential;

                using (var stream =
                    new FileStream("credentials.json", FileMode.Open, FileAccess.ReadWrite))
                {
                    string credPath = "token.json";

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create Google Docs API service.
                var service = new DocsService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = ApplicationName,
                });

                // Define request parameters.
                // String documentId = "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE";

                String documentId = "1rVrpAz0vgJt-_ui7xn-NGkT_bbrw5AA40Ih6OEggs1Q";
                DocumentsResource.GetRequest request = service.Documents.Get(documentId);

                // Prints the title of the requested doc:
                Document doc = request.Execute();

                //show doc title in message front end
                ViewData["Message"] = (doc.Title);


            }
...