Ton*_*Nam 4 c# google-calendar-api google-api google-api-dotnet-client service-accounts
我可以使用.NET快速入门教程访问Google Calendar API ,效果很好!
该教程的问题在于它使用Open Authentication or OAuth2.我想使用服务帐户身份验证执行相同操作.
(https://support.google.com/googleapi/answer/6158857?hl=en)
有人能举例说明如何使用服务帐户密钥文件访问我的日历吗?
我也试过尝试使用带有C#教程的Google Calendar API身份验证,但无法完成它.
我很好奇为什么你第一次尝试使用服务帐户教程不起作用.哪里错了?有错误吗?
记住服务帐户不是你.该服务帐户拥有自己的 Google日历帐户,因此,如果您尝试阅读其中一个"个人日历",则无法使用.您将不得不与服务帐户共享您的个人日历.
这是使用Json服务帐户密钥文件的另一个示例.
string[] scopes = new string[] { CalendarService.Scope.Calendar };
GoogleCredential credential;
using (var stream = new FileStream(serviceAccountCredentialFilePath, FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream)
.CreateScoped(scopes);
}
// Create the Calendar service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Calendar Authentication Sample",
});
Run Code Online (Sandbox Code Playgroud)