使用Google服务帐户,我正在尝试从域中获取CalendarLists和事件。两者都不起作用。我得到的只是一个JSON异常说:
Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
我将翻译成没有检索到的数据。
Google Calendar API和服务帐户是否有任何问题?
示例代码:
var req = CalendarService.CalendarList.List();
try
{
var list = req.Execute();
return list;
}
catch { }
或(在域中使用有效的电子邮件)
var req = CalendarService.Events.List("x@y.com");
var test = req.Execute();
var x = test.Items;
并且服务由以下人员创建:
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(settings.ServiceAccountEmail)
{
Scopes = new[] { CalendarService.Scope.Calendar },
User = string.Format("{0}@{1}", settings.AdminUsername, settings.Domain)
}.FromCertificate(settings.Certificate.Certificate));
return new CalendarService((new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "DotDash Fix",
}));
至少我实施的所有其他服务都有效。如果我使用连接到服务帐户的管理员用户登录,我可以完全看到日历。