есть ли способ отредактировать презентацию слайдов Google с С #

Я пытаюсь получить приложение С # для подачи данных в приложение слайдов Google, есть ли способ вставить текст в слайд с помощью API слайдов Google или API

это для презентации с живой демонстрацией, я пытался поискать на сайтах разработчиков Google, я ознакомился с презентацией, но не смог получить больше ничего

  using System;
    using System.IO.Ports;
    using System.Threading;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Slides.v1;
    using Google.Apis.Slides.v1.Data;
    using Google.Apis.Services;
    using Google.Apis.Util.Store;
    using System.Collections.Generic;
    using System.IO;
    using Google.Apis.Auth;
    using Google.Apis.Discovery;
    using Google.Apis.Drive;
    using Google.Apis.Drive.v3;
    using Google.Apis.Http;
    using Google.Apis.Logging;
    using Google.Apis.Requests;
    using Google.Apis.Slides;
    using Google.Apis.Testing;
    using Google.Apis.Upload;
    using Google.Apis.Util;
    using Google.Apis;


    public class PortChat
    {
        string tempatefile = "Section header";
        static bool _continue;
        static SerialPort _serialPort;

        static string[] Scopes = {DriveService.Scope.Drive, SlidesService.Scope.Drive};
        static string[] scope2 = { };
        static string ApplicationName = "Google Slides API .NET Quickstart";

        public static void Main()
        {
            UserCredential credential;

            using (var stream =

                new FileStream("C:/credentials/credentials.json", FileMode.Open, FileAccess.Read))

            {
                // The file token.json stores the user's access and refresh tokens, and is created 
                // automatically when the authorization flow completes for the first time. 
                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 Slides API service. 
            var service = new SlidesService(new BaseClientService.Initializer()

            {

                HttpClientInitializer = credential,

                ApplicationName = ApplicationName,

            });

            // Define request parameters. 
            String presentationId = "1qmbh4y5Zfzxo_mq5l8SzgLuKmKaC4DQzEib88a45js4";
            PresentationsResource.GetRequest request = service.Presentations.Get(presentationId);

            // Prints the number of slides and elements in a sample presentation: 
            // https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit 
            Presentation presentation = request.Execute();
            IList<Page> slides = presentation.Slides;
            Console.WriteLine("The presentation contains {0} slides:", slides.Count);

            for (var i = 0; i < slides.Count; i++)
            {

                var slide = slides[i];
                Console.WriteLine("- Slide #{0} contains {1} elements.", i + 1, slide.PageElements.Count);

            }

        }

    }

person dreamerz playz    schedule 09.07.2019    source источник
comment
Вы опубликовали много кода, и трудно понять, какой из них имеет отношение к проблеме, а какой нет. Создайте минимальный воспроизводимый пример с наименьшим количеством кода, чтобы нам было легче помочь.   -  person gunr2171    schedule 09.07.2019


Ответы (1)


Создание слайдов / текста или любые изменения работают с запросами.

  1. Вы создаете заявку
  2. Вы добавляете его в список
  3. Вы пакетно выполняете запросы

ниже приведен пример создания слайда:

        List<Request> requests = new List<Request>();
        String slideId = "MyNewSlide_001";

        Request rq = new Request();
        rq.CreateSlide = new CreateSlideRequest();
        rq.CreateSlide.ObjectId = slideId;
        rq.CreateSlide.InsertionIndex = 1;

        requests.Add(rq);

        // Execute the request.
        BatchUpdatePresentationRequest body = new BatchUpdatePresentationRequest();
        body.Requests = requests;
        BatchUpdatePresentationResponse response = service.Presentations.BatchUpdate(body, presentationId).Execute();
        CreateSlideResponse createSlideResponse = response.Replies[0].CreateSlide;

На странице API Google нет примеров .net, но проще всего работать с примеры java и измените для c #

person Zecbmo    schedule 02.04.2020