【问题标题】:Could not find member '@odata.type' on object of type 'Team'在“团队”类型的对象上找不到成员“@odata.type”
【发布时间】: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.ODataMicrosoft.Data.ODataCould 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


【解决方案1】:

虽然您可以将 Microsoft Graph SDK 重新指向 Beta 版本,但它仍将仅使用 v1.0 数据模型。要实际使用 Microsoft Graph Beta,您应该使用Microsoft Graph Beta SDK

Install-Package Microsoft.Graph.Beta -Version 0.8.0-preview

您还使用了一个已弃用的端点,该端点将在年底前被移除。来自documentation

此 API 正在被Create team 弃用,并将于 2019 年底移除。有关如何从组中创建团队的详细信息,请参阅Create team 中的示例 4 和 5 .

要创建Team from a Group,您可以像这样发出POST

await graphServiceClient
    .Groups[group.Id]
    .Team
    .Request()
    .PostAsync(team);

另外,请记住来自documentation 的这条注释:

如果组是在不到 15 分钟前创建的,则创建团队调用可能会由于复制延迟而失败并显示 404 错误代码。我们建议您重试创建团队调用 3 次,两次调用之间有 10 秒的延迟。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2012-06-30
    • 2016-05-25
    • 2014-04-27
    相关资源
    最近更新 更多