Google Calendar 基于 Google Calendar API v3,实现 ICalendarService 统一接口。
包信息
| 项 | 值 |
|---|---|
| NuGet 包 | Bitzsoft.Integrations.Calendar.Google |
| 实现接口 | ICalendarService |
| Provider ID | google |
| 鉴权方式 | 二选一:OAuth2 Access Token Bearer(推荐)或 API Key(query 参数) |
| 默认 BaseUrl | https://www.googleapis.com/calendar/v3 |
| 区域 | Global |
配置字段
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
AccessToken | string | 否* | — | OAuth2 Access Token(Bearer);优先级高于 ApiKey |
ApiKey | string | 否* | — | API Key(query 参数);未配置 AccessToken 时使用 |
BaseUrl | string | 否 | https://www.googleapis.com/calendar/v3 | Google Calendar API v3 基地址 |
HttpClientName | string | 否 | CalendarGoogle | 业务 HttpClient 命名 |
* AccessToken 与 ApiKey 至少配置一个。
配置 JSON 示例
{ "Calendar": { "Google": { "AccessToken": "ya29.xxxxxxxxxxxxxxxx", "BaseUrl": "https://www.googleapis.com/calendar/v3" } }}DI 注册
// 从配置节注册(默认节名 Calendar:Google)services.AddGoogleCalendar(configuration);
// 或用回调单独配置services.AddGoogleCalendar(options =>{ options.AccessToken = "ya29.xxxxxxxxxxxxxxxx";});使用示例
public class EventService{ private readonly ICalendarService _calendar;
public EventService(ICalendarService calendar) => _calendar = calendar;
public Task<CalendarEvent> CreateAsync(string summary, DateTimeOffset start, DateTimeOffset end) => _calendar.CreateEventAsync(new CreateEventRequest { Summary = summary, Start = start, End = end });
public Task<CalendarResult> AcceptAsync(string eventId) => _calendar.AcceptInvitationAsync(eventId);}依赖
| 包 | 说明 |
|---|---|
Bitzsoft.Integrations.Calendar | 日历服务抽象层 |
Bitzsoft.Integrations.Core | 公共基座 |
已知限制
- OAuth2 Access Token 有有效期,本包不自动刷新,需外部刷新后更新配置。
- API Key 鉴权能力受限(无法访问私有日历),仅适用于公开数据。