-1

我在 C# 控制台应用程序中使用 Graph API SDK,我想列出来自 Microsoft Teams 的所有班次数据。但我无法检索此类信息。这是我到目前为止所做的。

根据列出所有班次的文档,您必须提供团队 ID 才能检索班次,但是,就我而言,我必须从所有团队中检索所有班次。所以,我必须先检索团队列表。文档说,要检索所有团队,您必须首先检索组列表。我采用了相同的方法,以下是我使用的代码。

var groups = await graphClient
  .Groups.Request()
  .Filter("resourceProvisioningOptions/Any(x:x eq 'Team')")
  .GetAsync();

foreach (var group in groups)
{
    Console.WriteLine(group.DisplayName);
    var shifts = await graphClient
       .Teams[group.Id]
       .Schedule
       .Shifts
       .Request()
       .GetAsync();  
}

我能够检索组列表,但是,我无法检索班次列表。当它尝试检索 Shift 列表时,会发生以下错误:

Code: NotFound
Message: {
  "error":{
    "code":"NotFound",
    "message":"Sorry, the team was not found, or you may not have access to it.",
    "details":[],
    "innererror":{"code":"TeamNotFound"}
  }
}

Inner error:
    AdditionalData:
      request-id: c5ab5f5c-ec3d-463b-9b1f-0798734e94ce
      date: 11/11/2019 7:50:42 AM
      ClientRequestId: c5ab5f5c-ec3d-463b-9b1f-0798734e94ce

如果有任何帮助可以帮助我列出 Microsoft Teams 的所有班次列表,我将不胜感激。谢谢你。

4

1 回答 1

1

This error most likely occurs since schedule object is not provisioned. The point is List shifts endpoint expects schedule object to be provisioned. From Get schedule documentation:

During schedule provisioning, clients can use the GET method to get the schedule and look at the provisionStatus property for the current state of the provisioning. If the provisioning failed, clients can get additional information from the provisionStatusCode property.

In msgraph-sdk-dotnet whether schedule provisioned could be determined like this:

var schedule = await graphClient.Teams[group.Id].Schedule.Request().GetAsync();
if (schedule.ProvisionStatus == OperationStatus.Completed)
{  
    //...
}

Here is an updated example (which demonstrates how to retrieve shifts for provisioned schedule):

var groups = await graphClient.Groups.Request()
            .Filter("resourceProvisioningOptions/Any(x:x eq 'Team')")
            .GetAsync();
foreach (var group in groups)
{
     var schedule = await graphClient.Teams[group.Id].Schedule.Request().GetAsync();
     if (schedule.ProvisionStatus == OperationStatus.Completed)
     {
          var shifts = await graphClient.Teams[group.Id].Schedule.Shifts.Request().GetAsync();
         //...
     }         
}
于 2019-11-11T13:55:38.423 回答