1

我试图在没有结果的情况下使用educationClass模板在教育租户中创建一个团队,使用Microsoft Graph SDK for C#。这是官方网站(https://docs.microsoft.com/es-es/graph/api/team-post?view=graph-rest-beta&tabs=csharp)推荐的带有 BETA api 的代码。

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 Message: Invalid URL format specified in @odata.bind for owner

谢谢!

4

1 回答 1

2

我找到了解决问题的方法。我没有按照官方页面中的建议在字符串中创建和数组,而是使用了外部字符串数组:

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);
于 2020-07-21T17:54:28.670 回答