在“团队"类型的对象上找不到成员“@odata.type" [英] Could not find member '@odata.type' on object of type 'Team'

查看:87
本文介绍了在“团队"类型的对象上找不到成员“@odata.type"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将团队添加到之前使用 Microsoft Graph 创建的组.

I'm having trouble adding a Team to a Group previously created with Microsoft Graph.

我正在使用 Microsoft Graph .NET 客户端库 (1.19.0)使用 Microsoft Graph,遵循 .NET Core 教程 这里.

I am using the Microsoft Graph .NET Client Library (1.19.0) to work with Microsoft Graph, following the .NET Core tutorial here.

身份验证是通过客户端流程(控制台作为守护进程运行)进行的,我在构建 graphClient 或进行身份验证时没有问题:

Authentication is made with the client flow (console running as a deamon) and I have no problems building a graphClient or authenticating:

// 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);

但是将团队添加到新组时:

But when adding a Team to the new 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 时,结果是:

But when serializing the team-model to JSON the result is:

{"@odata.type":"microsoft.graph.team"}

这表明存在具有团队类型的 OData 成员.

Which would suggest that there is an OData Member with a type of Team.

我已尝试按照此处的建议添加 NuGet 包 Microsoft.AspNet.ODataMicrosoft.Data.OData:无法在TeamMemberSettings"类型的对象上找到成员@odata.type",但是没有用.

I've tried to add both NuGet packages Microsoft.AspNet.OData and Microsoft.Data.OData as per this suggestion here: Could not find member '@odata.type' on object of type 'TeamMemberSettings', but it didn't work.

我还尝试使用 HttpRequest 直接调用端点,结果相同.我还尝试在 .NET Core 和 .Net Framework 应用中使用相同的代码.

I've also tried calling the endpoint directly with an HttpRequest which yielded the same result. I also tried using the same code in a .NET Core and .Net Framework app.

推荐答案

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

While you can repoint the Microsoft Graph SDK to the Beta version, it will still only use the v1.0 data models. To actually use the Microsoft Graph Beta, you should use the Microsoft Graph Beta SDK.

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

您还使用了一个已弃用的端点,该端点将在年底前移除.来自 文档:

You're also using a deprecated endpoint that will be removed before the end of the year. From the documentation:

此 API 正在被弃用,以支持 创建团队,将于2019年底移除.如何从群组创建团队的详细信息请参见创建团队.

This API is in the process of being deprecated in favor of Create team, and will be removed by the end of 2019. For details about how to create a team from a group, see examples 4 and 5 in Create team.

创建来自一个组的团队,你发出一个 POST 像这样:

To create a Team from a Group, you issue a POST like this:

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

另外,请记住 文档:

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

If the group was created less than 15 minutes ago, it's possible for the Create team call to fail with a 404 error code due to replication delays. We recommend that you retry the Create team call three times, with a 10 second delay between calls.

这篇关于在“团队"类型的对象上找不到成员“@odata.type"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆