【发布时间】:2018-08-06 21:59:56
【问题描述】:
我正在尝试从 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:line 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);
【问题讨论】:
-
根据 API 参考,
files.export用于 Google 文档。评论developers.google.com/drive/api/v3/manage-downloads -
您可以使用 Apps Script API 的 projects.getContent 从项目中下载脚本。您可以在here 看到该文档。使用此 API 时,请注意范围。
-
实际上,不完全是,但是您的回复使我深入该页面以查找文档。使用具有 MIME 类型“application/vnd.google-apps.script+json”的相同代码允许应用程序脚本正确转换为 JSON。下一个挑战是将 JSON 内容解析为特定文件。感谢您的帮助!
标签: c# google-apps-script google-drive-api google-api-dotnet-client