c# - 使用 REST API v3 使用 C# 导出 Google Apps 脚本项目
问题描述
我正在尝试从 Google Apps 脚本项目下载.gs和.html文件;但是,由于文档不足,这被证明是一项艰巨的任务。
我目前正在使用 Drive Rest v3 API。
我不断收到的错误是:
服务驱动器抛出异常:
Google.GoogleApiException:Google.Apis.Requests.RequestError 不支持请求的转换。[400] 错误 [ 消息[不支持请求的转换。] Location[convertTo - parameter] Reason[badRequest] Domain[global] ] 在 C:\Apiary\2018-05-30.11-21-16\Src\Support\Google.Apis\Download\MediaDownloader.cs: 323 中的 Google.Apis.Download.MediaDownloader.d__31.MoveNext() Google.Apis.Download.MediaDownloader+DownloadProgress
我感觉 MIME 类型可能已关闭。这是代码。
DriveService ds = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
FilesResource.ExportRequest exp = ds.Files.Export(id,"application/vnd.google-apps.script");
//exp.Alt = DriveBaseServiceRequest<string>.AltEnum.Json;
//FilesResource.GetRequest get = new FilesResource.GetRequest(ds, id);
var streamer = new System.IO.MemoryStream();
exp.MediaDownloader.ProgressChanged +=
(IDownloadProgress progress) =>
{
switch (progress.Status)
{
case DownloadStatus.Downloading:
{
Console.WriteLine(progress.BytesDownloaded);
break;
}
case DownloadStatus.Completed:
{
Console.WriteLine("Download complete.");
break;
}
case DownloadStatus.Failed:
{
Console.WriteLine("Download failed.");
Console.WriteLine(progress.Exception);
break;
}
}
};
IDownloadProgress i = exp.DownloadWithStatus(streamer);
解决方案
谷歌在 2017 年推出了clasp,这是一个用于导入和导出应用程序脚本项目并在本地开发的官方工具。这是从 Google Apps 脚本项目下载 .gs 和 .html 文件的推荐方式。试试扣拉命令,效果很好!
推荐阅读
- spring-integration - MongoDbMessageStore 可以在几个 JVM 之间共享吗?
- google-cloud-dataflow - 使用 ClickhouseIO 时如何确保每秒插入 1 次
- python - 在 kivy/python 中的应用程序中自动计算结果
- javascript - 将值从 HTML/Javascript 传递到 Flask
- postgresql - 如何创建参数化 XPath 查询
- javascript - 如何在javascript中将当前系统日期格式化为DD-MON-YYYY HH12:MI:SS:AM格式
- java - org.postgresql.util.PSQLException:查询没有结果
- api - 如何在 Dart/Flutter 中使用 Flask Server API 将图像作为请求发布?
- c++ - 如何找到 R 包 bsts 的 C++ 代码?
- javascript - 如何在散景热图中删除/添加行并保持行高?