使用Microsoft Graph创建新日历

时间:2020-02-06 13:55:02

标签: c# office365 microsoft-graph-api

我已设置user.read, calendars.readwrite许可,并且可以成功进行身份验证。但是我得到了:

Microsoft.Graph.ServiceException : Code: ErrorInvalidRequest
Message: The OData request is not supported.

我的测试看起来像

var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(request => {
    request.Headers.Authorization = new AuthenticationHeaderValue("bearer", _authenticationResult.AccessToken);
    return Task.FromResult(0);
}));

var user = await graphClient.Me.Request().GetAsync();

Console.WriteLine(user.Id + ": " + user.DisplayName + " <" + user.Mail + ">");
await graphClient.Me.Calendar.Request().CreateAsync(new Calendar(){Name = "test"});

2 个答案:

答案 0 :(得分:1)

实际上是

await graphClient.Me.Calendars.Request().AddAsync(new Calendar(){Name = "test"});

而不是

graphClient.Me.Calendar

答案 1 :(得分:-1)

尝试一下:

await graphClient.Me.Calendar.Request().AddAsync(new Calendar(){Name = "test"});

源:Create calendar