【发布时间】:2019-10-30 09:51:50
【问题描述】:
我在将团队添加到之前使用 Microsoft Graph 创建的组时遇到问题。
我正在使用 Microsoft Graph .NET Client Library (1.19.0) 来使用 Microsoft Graph,遵循 .NET Core 教程 here。
使用客户端流程进行身份验证(控制台作为守护程序运行),我在构建 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 应用程序中使用相同的代码。
【问题讨论】:
标签: c# microsoft-graph-api microsoft-graph-sdks microsoft-graph-teams