谷歌日历API 403禁止事件创建

本文关键字:事件 创建 禁止 日历 API 谷歌 | 更新日期: 2023-09-27 18:01:20

我被卡住了,谷歌的文档根本没有任何帮助。

我已经用适当的作用域验证了应用程序。我得到了同意屏幕,刷新令牌被正确存储。

我可以查看用户的日历,但是当我试图插入一个事件时,我得到403 Forbidden错误。

这是我用来添加事件的代码。(在我添加离线访问之前,相同的代码正在工作)

UserCredential credential = GetCredential(user.Username);
if (credential != null)
{
    CalendarService service = new CalendarService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "OO Software Service System",
    });
    //Create the event.
    Event e = new Event()
    {
        Attendees = new List<EventAttendee> 
        {
            new EventAttendee() 
            {
                Id = user.GoogleId, 
                Email = user.Username
            }
        },
        Start = new EventDateTime()
        {
            DateTime = start
        },
        End = new EventDateTime()
        {
            DateTime = end
        },
        Created = DateTime.Now,
        Summary = eventName
    };
    //Insert the event into the calendar.
    e = service.Events.Insert(e, "primary").Execute();

Scope and Credentials:

public static string[] GetScopes()
{
    return new string[] { CalendarService.Scope.Calendar, PlusService.Scope.PlusMe };
}
public static UserCredential GetCredential(string username)
{
    return GoogleWebAuthorizationBroker.AuthorizeAsync(
        GetSecrets(),
        GetScopes(),
        username,
        CancellationToken.None,
        new ServiceSystemDataStore()).Result;
}

有没有人能说明问题是什么?错误提示403禁止域名并不是很有帮助。

我当然已经在Google Console中启用了必要的api,并且范围是正确的,因为我通过使用同意屏幕对用户进行身份验证来获得刷新令牌。

谷歌日历API 403禁止事件创建

显然我有错误的EventAttendee.Id。这个Id是在我对用户进行身份验证时提供的,所以我错误地认为它应该被提供——我错了。

有时候你只需要把问题写下来自己看看答案