我无法将团队添加到以前使用 Microsoft Graph 创建的组。
我正在使用Microsoft Graph .NET 客户端库(1.19.0) 来使用 Microsoft Graph,遵循此处的 .NET Core 教程。
graphClient
使用客户端流程进行身份验证(控制台作为守护程序运行),我在构建或身份验证时没有问题:
// Auth info
var tenantId = "xxx";
var clientId = "xxx";
var clientSecret = "xxx";
var scopes = new List<string> { "https://graph.microsoft.com/.default" };
// Create ConfidentialClientApplication
var confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, tenantId)
.WithClientSecret(clientSecret)
.Build();
// Create authenticationProvider
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication, scopes[0]);
// Create graph client
// Use graph BETA endpoint
var baseUrl = "https://graph.microsoft.com/beta/";
var graphServiceClient = new GraphServiceClient(baseUrl, authenticationProvider);
或创建一个组:
var groupName = "Team group";
var groupDescription = "Awesome group";
var group = new Group
{
DisplayName = groupName,
Description = groupDescription,
GroupTypes = new List<string> { "Unified" },
Visibility = "Private",
MailNickname = groupName.Replace("", string.Empty).ToLower(),
MailEnabled = false,
SecurityEnabled = false
};
// Send the POST request to create group
group = await graphServiceClient.Groups.Request().AddAsync(group);
但是在将团队添加到新组时:
var team = new Team();
await graphServiceClient
.Groups[group.Id]
.Team
.Request()
.PutAsync(team);
我收到以下错误:
Code: InvalidRequest
Message: Could not find member '@odata.type' on object of type 'Team'. Path '['@odata.type']', line 1, position 15.
Inner error:
AdditionalData:
request-id: xxx
date: 2019-10-30 09:12:04
ClientRequestId: xxx
但是当将团队模型序列化为 JSON 时,结果是:
{"@odata.type":"microsoft.graph.team"}
这表明存在具有团队类型的 OData 成员。
我已经尝试添加两个 NuGet 包Microsoft.AspNet.OData
,并Microsoft.Data.OData
按照这里的建议:Could not find member '@odata.type' on object of type 'TeamMemberSettings',但它没有用。
我还尝试使用HttpRequest
产生相同结果的直接调用端点。我还尝试在 .NET Core 和 .Net Framework 应用程序中使用相同的代码。