如何使用C#通过Microsoft Graph创建一个带有模板educationClass的团队



我正在尝试使用educationClass模板在教育租户中创建一个团队,通常使用Microsoft Graph SDK for C#。这是官方网站推荐的带有BETA api的代码(https://learn.microsoft.com/es-es/graph/api/team-post?view=graph-休息测试版&tabs=csharp(。

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var team = new Team
{
    DisplayName = "My Sample Team",
    Description = "My Sample Team’s Description",
    AdditionalData = new Dictionary<string, object>()
    {
        {"template@odata.bind", "https://graph.microsoft.com/beta/teamsTemplates('educationClass')"},
        {"owners@odata.bind", "["https://graph.microsoft.com/beta/users('userId')"]"}
    }
};
await graphClient.Teams
    .Request()
    .AddAsync(team);

当我执行此代码时,它会引发以下错误:Microsoft.Graph.ServiceException:"code:BadRequest"消息:在@odata.bind中为所有者指定的URL格式无效

谢谢!

我找到了这个问题的解决方案。我没有像官方页面上建议的那样在字符串中创建和数组,而是使用了一个外部字符串数组:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
string[] owners = new string[1];
owners[0] = "https://graph.microsoft.com/beta/users/userId";
var team = new Team
{
    DisplayName = "My Sample Team",
    Description = "My Sample Team’s Description",
    AdditionalData = new Dictionary<string, object>()
    {
        {"template@odata.bind", "https://graph.microsoft.com/beta/teamsTemplates('educationClass')"},
        {"owners@odata.bind", owners}
    }
};
await graphClient.Teams
    .Request()
    .AddAsync(team);

相关内容

  • 没有找到相关文章

最新更新