我创建了服务帐户,我向这个帐户公开了几个文件,一旦我想下载文件,就会抛出异常
Google.Apis.Requests.RequestError 不良要求[400] 错误[ 消息[错误请求]位置[ - ]原因[badRequest]域[全局] ]
var certificate = new X509Certificate2("*******.p12", "notasecret", X509KeyStorageFlags.Exportable);
try
{
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("*******..com")
{
Scopes = scopes
}.FromCertificate(certificate));
// Create the service.
DriveService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Daimto Drive API Sample",
});
var files = service.Files.List().Execute().Files;
var request = service.Files.Get(files.First().Id);
var stream = new System.IO.MemoryStream();
request.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.");
break;
}
}
};
request.Download(stream);