有什么方法可以通过c#

时间:2019-07-09 13:53:38

标签: c# google-api google-slides-api

我正在尝试使用C#应用程序将数据输入到Google幻灯片应用程序中,是否可以使用Google幻灯片api或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);

            }

        }

    }

1 个答案:

答案 0 :(得分:0)

创建幻灯片/文本或进行任何更改都可以处理请求。

  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;

google API页面上没有.net的示例,但是最容易解决java examples并为c#进行修改