Google Calendar API 403禁止创建活动

时间:2015-07-06 08:03:30

标签: c# asp.net-mvc-4 google-calendar-api

我被困住了,Googles的文档根本没有任何帮助。

我已使用适当的范围对应用进行了身份验证。我获得了同意屏幕,并且正确存储了刷新令牌。

我可以查看用户的日历,但是当我尝试插入事件时,我收到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();

范围和凭证:

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 Forbidden域并不是很有帮助。

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

1 个答案:

答案 0 :(得分:0)

显然我错了EventAttendee.Id。当我对用户进行身份验证时提供了此ID,因此我错误地认为它应该被提供 - 我错了。

有时候你只需要写下问题就可以找到自己的答案。

相关问题