Microsoft graph api 在GraphAPI中创建团队始终返回null

Microsoft graph api 在GraphAPI中创建团队始终返回null,microsoft-graph-api,microsoft-graph-teams,Microsoft Graph Api,Microsoft Graph Teams,我正在使用GraphAPI SDK在Microsoft团队中创建一个新团队: var newTeam = new Team() { DisplayName = teamName, Description = teamName, AdditionalData = new Dictionary<string, object>() {

我正在使用GraphAPI SDK在Microsoft团队中创建一个新团队:

        var newTeam = new Team()
        {
            DisplayName = teamName,
            Description = teamName,
            AdditionalData = new Dictionary<string, object>()
            {
                {"template@odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"}
            },
            Members = new TeamMembersCollectionPage()
            {
                new AadUserConversationMember
                {
                    Roles = new List<String>()
                    {
                        "owner"
                    },
                    AdditionalData = new Dictionary<string, object>()
                    {
                        {"user@odata.bind", $"https://graph.microsoft.com/v1.0/users/{userId}"}
                    }
                }
            }
        };

        var team = await this.graphStableClient.Teams
            .Request()
            .AddAsync(newTeam);
var newTeam=newTeam()
{
DisplayName=团队名称,
Description=团队名称,
AdditionalData=新字典()
{
{"template@odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates(‘标准’)“}
},
成员=新团队成员集合页面()
{
新AadUserConversationMember
{
角色=新列表()
{
“所有者”
},
AdditionalData=新字典()
{
{"user@odata.bind", $"https://graph.microsoft.com/v1.0/users/{userId}}
}
}
}
};
var team=等待this.graphStableClient.Teams
.Request()
.AddAsync(newTeam);

问题是我总是得到空值。根据该方法,返回202响应(teamsAsyncOperation),但SDK中的AddAsync方法返回一个团队对象。有没有办法获取跟踪url以检查团队创建是否已使用SDK完成?

文档和工作SDK的工作方式不同。。。正如他们在microsoft graph docs/issues/10840中所写的那样,如果我们像contoso airlines团队示例中那样使用HttpRequestMessage,我们只能获得teamsAsyncOperation标题值。他们写信给问这个问题的人,看看加入的团队:):)

var newTeam=newTeam()
{
DisplayName=model.DisplayName,
Description=型号.Description,
AdditionalData=新字典
{
["template@odata.bind“]=$”{graph.BaseUrl}/teamsTemplates('standard')”,
[“成员”]=所有者。ToArray()
}
};
//我们不能使用'wait client.Teams.Request().AddAsync(newTeam)'
//由于我们无法取回团队ID(对象始终为空):(
BaseRequest=(BaseRequest)graph.Teams.request();
request.ContentType=“application/json”;
request.Method=“POST”;
字符串位置;
使用(HttpResponseMessage response=wait request.SendRequestAsync(newTeam,CancellationToken.None))
location=response.Headers.location.ToString();
//看起来像:/teams('7070b1fd-1f14-4a06-8617-254724d63cde')/operations('c7c34e52-7ebf-4038-b306-f5af2d9891ac'))
//但记录为:/teams/7070b1fd-1f14-4a06-8617-254724d63cde/operations/c7c34e52-7ebf-4038-b306-f5af2d9891ac
//->此拆分支持两者
string[]locationParts=location.Split(新的[]{'\''''',/','('',')},StringSplitOptions.RemoveEmptyEntries);
字符串teamId=locationParts[1];
字符串操作ID=位置部件[3];
//在第一次查询之前,我们必须等待几秒钟,否则我们将得到404
int DELAYIN毫秒=5_000;
while(true)
{
等待任务。延迟(延迟毫秒);
//让我们看看团队创建过程有多远
TeamsAsyncOperation操作=等待图。团队[teamId]。操作[operationId]。请求().GetAsync();
if(operation.Status==TeamsAsyncOperationStatus.successed)
打破
if(operation.Status==TeamsAsyncOperationStatus.Failed)
抛出新异常($“未能创建团队“{newTeam.DisplayName}”:{operation.Error.Message}({operation.Error.Code})”;
//根据文件,我们应该在通话之间等待30秒以上
// https://docs.microsoft.com/en-us/graph/api/resources/teamsasyncoperation?view=graph-rest-1.0
延迟毫秒数=30_000;
}
//最后,和你的团队一起做点什么。。。
我从…找到了一个解决方案,试过了,看到它在工作

 var newTeam = new Team()
{
    DisplayName = model.DisplayName,
    Description = model.Description,
    AdditionalData = new Dictionary<string, object>
    {
        ["template@odata.bind"] = $"{graph.BaseUrl}/teamsTemplates('standard')",
        ["members"] = owners.ToArray()
    }
};

// we cannot use 'await client.Teams.Request().AddAsync(newTeam)'
// as we do NOT get the team ID back (object is always null) :(
BaseRequest request = (BaseRequest)graph.Teams.Request();
request.ContentType = "application/json";
request.Method = "POST";

string location;
using (HttpResponseMessage response = await request.SendRequestAsync(newTeam, CancellationToken.None))
    location = response.Headers.Location.ToString();

// looks like: /teams('7070b1fd-1f14-4a06-8617-254724d63cde')/operations('c7c34e52-7ebf-4038-b306-f5af2d9891ac')
// but is documented as: /teams/7070b1fd-1f14-4a06-8617-254724d63cde/operations/c7c34e52-7ebf-4038-b306-f5af2d9891ac
// -> this split supports both of them
string[] locationParts = location.Split(new[] { '\'', '/', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
string teamId = locationParts[1];
string operationId = locationParts[3];

// before querying the first time we must wait some secs, else we get a 404
int delayInMilliseconds = 5_000;
while (true)
{
    await Task.Delay(delayInMilliseconds);

    // lets see how far the teams creation process is
    TeamsAsyncOperation operation = await graph.Teams[teamId].Operations[operationId].Request().GetAsync();
    if (operation.Status == TeamsAsyncOperationStatus.Succeeded)
        break;

    if (operation.Status == TeamsAsyncOperationStatus.Failed)
        throw new Exception($"Failed to create team '{newTeam.DisplayName}': {operation.Error.Message} ({operation.Error.Code})");

    // according to the docs, we should wait > 30 secs between calls
    // https://docs.microsoft.com/en-us/graph/api/resources/teamsasyncoperation?view=graph-rest-1.0
    delayInMilliseconds = 30_000;
}

// finally, do something with your team...