gpt4 book ai didi

c# - 使用服务帐户身份验证访问 Google Calendar API

转载 作者:太空狗 更新时间:2023-10-30 00:30:14 25 4
gpt4 key购买 nike

我能够使用 .NET Quickstart 访问 Google Calendar API教程,效果很好!

该教程的问题在于它使用了 Open Authentication 或 OAuth2。我想用 Service Account Authentication 做同样的事情.

( https://support.google.com/googleapi/answer/6158857?hl=en )

有人可以举例说明如何使用服务帐户 key 文件访问我的日历吗?

我试过也试过使用Google Calendar API Authentication with C#教程,但无法完成。

最佳答案

我很好奇为什么您第一次尝试使用服务帐户教程没有成功。什么问题?有错误吗?

请记住服务帐户不是您。该服务帐户有其自己的 Google 日历帐户,因此如果您尝试阅读您的“个人日历”之一,它将无法工作。您将不得不与服务帐户共享您的个人日历。

这是另一个使用 Json service account key file 的例子.

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",
});

关于c# - 使用服务帐户身份验证访问 Google Calendar API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40144018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com