google-api - 创建多个文件夹后,Google Drive Api (.Net) 返回错误
问题描述
我正在 MVC .Net(VS 2019 + Google Drive Api v3)中开发一个网络应用程序。我们正在使用一个服务帐户来使用一个简单的谷歌帐户中的共享文件夹。我们需要为学生的每项任务创建一个文件夹。我们有 2000 名学生,他们平均每月有 10 个任务。所以我们的谷歌驱动器中会有很多文件夹。因此,我决定使用控制台应用程序进行一些测试,并在创建多个文件夹后发现一些错误。有人知道 Google Drive Api 是否对创建多个文件夹有某种限制?下面是一个控制台应用程序,用打印图像证明这一点。
namespace DriveQuickstart
{
class Program
{
static void Main(string[] args)
{
string[] Scopes = { DriveService.Scope.DriveReadonly, DriveService.Scope.DriveFile };
ServiceAccountCredential credential;
using (var stream =
new FileStream("key.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream)
.CreateScoped(Scopes)
.UnderlyingCredential as ServiceAccountCredential;
}
// Create Drive API service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Test App",
});
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
for (int i = 0; i < 50; i++)
{
body.Name = "Test_" + Guid.NewGuid().ToString();
body.Description = "Created by me!";
body.MimeType = "application/vnd.google-apps.folder";
body.Parents = new List<string> { "1hLsDTub8bhlVS2ax34P8wGx5RsD0n8MA" };
try
{
service.Files.Create(body).Execute();
Console.WriteLine("Folder " + (i+1).ToString() + " created.");
}
catch (Exception e)
{
Console.WriteLine("Error = " + e.InnerException.Message);
}
}
}
}
}
内部异常错误:“无法从传输连接读取数据。它被远程服务器强制取消”。
解决方案
推荐阅读
- python - 在使用 tkinter 中传递的参数进行线程处理时中断 while 循环
- google-cloud-platform - 在 GCP 实例上运行脚本终止
- git - bitbucket rest api 获取从源 (fromRef) 分支到目标分支 (fromRef) 创建的拉取请求 (OPEN) 列表
- powershell - 通过 Power Shell 批量删除 Office 365 中的空子文件夹
- python - 当文件更新时,用于监视目录的 Python 脚本会触发两次。为什么?
- java - 我可以在 maven-release 插件之后运行自定义 maven 插件吗?
- architecture - 在 DDD 的上下文中应该如何处理事件订阅和分发
- php - 如何使用 json laravel 的单个键获取多个值?
- javascript - 在调整浏览器窗口大小时按住背景图像
- c# - Asp.Net Core Razor 页面,无法从其他视图/剃须刀模型访问会话变量