【发布时间】:2019-07-09 13:53:38
【问题描述】:
我正在尝试让 C# 应用程序将数据输入谷歌幻灯片应用程序,有没有办法使用谷歌幻灯片 api 或 api 将文本插入幻灯片
这是一个带有现场演示的演示文稿,我尝试查看谷歌开发者网站,我已经访问了演示文稿,但无法获得更多内容
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);
}
}
}
【问题讨论】:
-
您已经发布了 很多 代码,很难确定哪些与问题相关或不相关。请使用最少的代码创建minimal reproducible example,以便我们更轻松地提供帮助。
标签: c# google-api google-slides-api