1 回答
TA贡献1831条经验 获得超9个赞
概括 :
调用谷歌云 oauth2 保护资源
从您的服务器到谷歌服务器
无需用户交互
访问您自己的数据
使用 C#
代码 :
var private_key = @"-----BEGIN PRIVATE KEY-ccc-END PRIVATE KEY-----\n";
string calendarId = @"xxxxxxxxxxxxx@group.calendar.google.com";
var client_email = @"my-google-calender@xxx.iam.gserviceaccount.com";
var credential =
new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(client_email)
{
Scopes = new string[] { CalendarService.Scope.Calendar }
}.FromPrivateKey(private_key));
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
});
使用服务方法获取数据
可以从此链接生成私钥和 client_email
日历 ID 可在 calendar.google.com 上找到
您必须与 client_email 共享您的日历查看演示
Google You You
Pay + Pay + Pay +
Google Google You
Manage Manage Manage%
+----------+ +----------+ +----------+
| Gmail | | | | |
| Calendar | | G Suite | | Google |
| drive | | | | Cloud |
| | | | | |
+----^-----+ +----+-----+ +------+---+
| ^ ^
| | |
| | |
| | |
+-------------------------------------------------------------+
| | | | |
| | | | |
| | | Google | |
| | | Oauth2 | |
| | | Server | |
| | | | |
| | | | |
+-------------------------------------------------------------+
| | |
| | +----------------+ |
| | | | |
| | | | | No
| |require | | | Consent
| |admin | | |
| |consent | | |
|require | | +-------+
|user | | |
|consent +---------+ Your app |
| | |
| | |
| | |
| | |
+-------------------------+ |
| |
| |
| |
+----------------+
You
Pay +
You
Manage
https://stackoverflow.com/questions/54066564/google-calendar-api-with-asp-net
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报