c# - 如何使用 C Sharp 创建谷歌电子表格?
问题描述
我收到这个错误
Google.GoogleApiException:'Google.Apis.Requests.RequestError
文件未找到:。[404]
调用 CreateSpreadsheet() 时出现错误 [ 消息 [找不到文件:.] 位置 [文件 ID - 参数] 原因 [未找到] 域 [全局]
(出于我的安全考虑,凭据略有不同。)
public Google.Apis.Drive.v3.Data.File CreateSheet()
{
string[] scopes = new string[] { DriveService.Scope.Drive,DriveService.Scope.DriveFile,};
var clientId = "123456337-wajklowlksflmxiowerasjdflsl.apps.googleusercontent.com";
var clientSecret = "kkslfdkiwowol_ssdwerss";
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret
},
scopes,
Environment.UserName,
CancellationToken.None,
new FileDataStore("MyAppsToken")).Result;
DriveService _service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyAppName"
});
var _parent = ""; //ID of folder if you want to create spreadsheet in specific folder
var filename = "helloworld";
var fileMetadata = new Google.Apis.Drive.v3.Data.File()
{
Name = filename,
MimeType = "application/vnd.google-apps.spreadsheet",
//TeamDriveId = teamDriveID, // IF you want to add to specific team drive
};
FilesResource.CreateRequest request = _service.Files.Create(fileMetadata);
request.SupportsTeamDrives = true;
fileMetadata.Parents = new List<string> { _parent }; // Parent folder id or TeamDriveID
request.Fields = "id";
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
var file = request.Execute();
MessageBox.Show("File ID: " + file.Id);
return file;
}
解决方案
推荐阅读
- python - 在pyqt5中动态更改数据破折号
- javascript - 使用 ApiService 将 redux 工具包方法 createAsyncThunk 与 Angular HttpClient 集成
- php - Symfony 路由主机正则表达式
- linux - 使用 containerd 为容器创建同级进程
- firebase - 想要在flutter中通过底部导航栏的总价
- database - 如何从 laravel 中的用户的数据透视表中获取角色名称?
- javascript - 如何从 Keycloak 授权服务策略中请求的资源 URI 中获取路径参数?
- serialization - avro-rs 解释 `uuid` 给出 SerdeError
- java - 致命异常:java.lang.IndexOutOfBoundsException setSpan (4 ... 4) Android Studio
- flutter - 如何在 Flutter/Dart 中测试多个列表项的顺序?