反序列化JSON凭据Data C#Google表格API时出错
作者:互联网
我目前正在尝试使用服务帐户访问GoogleSheets API – 我遇到的问题是我的.json文件.
这是我的代码:
try
{
string[] scopes = new string[] { SheetsService.Scope.Spreadsheets, SheetsService.Scope.SpreadsheetsReadonly }; // Put your scopes here
var stream = new FileStream("my_application_secret.json", FileMode.Open, FileAccess.Read);
var credential = GoogleCredential.FromStream(stream);
credential = credential.CreateScoped(scopes);
SheetsService service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "myApplication",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine("Create service account myApplicationServiceAccount failed : " + ex.Message);
throw new Exception("Create ServiceAccount Failed : ", ex);
}
这启动了我的错误,内容如下:
Create service account myApplicationServiceAccount failed : Error deserializing JSON credential data.
但我在网上找到的所有内容都说我上面所说的应该有用.
我还有什么比这个.json文件更多的东西吗?
解决方法:
事实证明 – 因为我支持旧版本的.NET(4及以下版本),我使用的是较旧版本的Google表格API.
但是Newtonsoft.JSON包也已经过时了.更新了,现在它正在运行.
标签:json,c,google-api,service-accounts,google-sheets-api 来源: https://codeday.me/bug/20190608/1198236.html