【问题标题】:How to create a event in MS Teams Calendar using MS Graph API from a backend service如何使用来自后端服务的 MS Graph API 在 MS Teams 日历中创建事件
【发布时间】:2020-06-16 01:12:24
【问题描述】:

我是使用 Microsoft Graph API 的新手,我真的很想在我的 .Net Core 应用程序中实现图形 API 的可能性。我决定创建一个示例应用程序,在 MS Teams 应用程序中创建会议。我已经完成了下面列出的步骤。

  1. 我在 Azure Active Directory 中注册了一个新应用程序。
  2. 分配“Calendars.Read”和“Calendars.ReadWrite”(权限类型 - 应用程序)权限。

我知道有两种类型的权限验证。 DelegatedApplication

权限

代码

try
        {
            var config = this.LoadAppSettings();

            GraphServiceClient graphClient = GetAuthenticatedGraphClient(config);

            var @event = new Event
            {
                Subject = "My event by ragesh",
                Start = new DateTimeTimeZone
                {
                    DateTime = "2020-06-11T07:44:21.358Z",
                    TimeZone = "UTC"
                },
                End = new DateTimeTimeZone
                {
                    DateTime = "2020-06-18T07:44:21.358Z",
                    TimeZone = "UTC"
                }
            };

            await graphClient.Me.Events
             .Request()
             .AddAsync(@event);


        }
        catch (Exception ex)
        {
            throw ex;
        }

但是当我执行代码以在图形 API 中创建 events 时,它会显示身份验证错误。

错误

【问题讨论】:

    标签: api asp.net-core oauth-2.0 microsoft-graph-api microsoft-graph-teams


    【解决方案1】:

    当您使用应用程序权限时,您不能使用/me API url 段,因为没有经过身份验证的用户。您必须改为使用/users/<user-id>

    您使用的是 .NET SDK,因此您不能使用graphClient.Me,您必须使用graphClient.Users[userId]

    【讨论】:

      猜你喜欢
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多