尝试从Google云端硬盘下载Excel(* .xlsx)文件。
调用DriveService.HttpClient.GetByteArrayAsync()时出现此错误:
System.Net.Http.HttpRequestException 响应状态代码不表示成功:500(内部服务器错误
我创建了一个捕获/重试机制,该机制似乎可以尝试3次。我仍然想要修复
byte[] byteArray = Encoding.UTF8.GetBytes(map.Credentials);
string[] scopes = new string[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile };
UserCredential credential;
using (var stream = new MemoryStream(byteArray))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
DriveService driveService = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
string path = "https://www.googleapis.com/drive/v3/files/" + map.Path + "?alt=media";
var x = driveService.HttpClient.GetByteArrayAsync(path);
byte[] arrBytes = x.Result; // Randomly throws exception