使用图表 API 错误添加 MS Teams 网站选项卡
Add MS Teams website tab using graph API error
上下文:
我正在尝试向 MS Teams 中的现有频道添加一个新的网站选项卡,然后获取新创建的选项卡的 ID。
问题:
我可以创建新选项卡,但我从图表中收到 "BadRequest" 异常:
消息:值不能为空。参数名称:entity
有趣的是,该选项卡是在正确的团队和频道中的 MS Teams 中创建并显示的,但我无法以任何方式获取它的 ID。
我的代码:
var tab = await _graphClient.Teams[teamId].Channels[channelId].Tabs.Request().WithMaxRetry(3).AddAsync(
new TeamsTab
{
DisplayName = "New Tab",
AdditionalData = new Dictionary<string, object>
{
["teamsApp@odata.bind"] =
$"{_teamsFactory.GraphV1Endpoint}/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web"
},
Configuration = new TeamsTabConfiguration
{
EntityId = null,
WebsiteUrl = $"{_appUrl}/1",
ContentUrl = $"{_appUrl}/1",
RemoveUrl = null,
}
}
);
就像我在上面写的那样,此代码有效并创建了选项卡,但 GraphServiceClient 在分配 tab 变量之前抛出异常。
当我尝试在 Graph Explorer 中获取选项卡列表时
https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channelid}/tabs
我收到错误回复:
{
"error": {
"code": "InternalServerError",
"message": "Failed to execute request.",
"innerError": {
"request-id": "a03654e8-37a7-4fbb-8052-6a1b11721234",
"date": "2020-02-24T15:11:54"
}
}
}
我认为您可能需要为 "EntityId" 设置一个值 - 基本上只是一个字符串值,以唯一地 "name" 您的选项卡。它不是 "DisplayName",而是选项卡的字符串 "id"。
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/tabs
{
"displayName": "My Contoso Tab",
"teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
"configuration": {
"entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
"contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
"websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
"removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
}
}
请看Add Tab to a channel using Graph API
编辑 1:能否请您检查一下您是否具有添加选项卡的适当权限?
Edit2:你能试试下面的代码吗?
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var teamsTab = new TeamsTab
{
DisplayName = "WebsiteTab",
AdditionalData = new Dictionary<string, object>()
{
{"teamsApp@odata.bind","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web"}
},
Configuration = new TeamsTabConfiguration
{
EntityId = null,
ContentUrl = "https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-context",
RemoveUrl = null,
WebsiteUrl = "https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-context"
}
};
await graphClient.Teams["TeamId"].Channels["ChannelId"].Tabs
.Request()
.AddAsync(teamsTab);
最后我找到了 "solution",不过更好的名称是解决我的问题的方法。为了让它工作,我必须在 TeamsTabConfiguration
中将 ODataType
设置为 null
。就这样。代码应如下所示:
var tab = await _graphClient.Teams[teamId].Channels[channelId].Tabs.Request().WithMaxRetry(3).AddAsync(
new TeamsTab
{
DisplayName = TabTitle,
ODataBind = $"{_teamsFactory.GraphV1Endpoint}/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web",
Configuration = new TeamsTabConfiguration
{
ODataType = null,
EntityId = null,
WebsiteUrl = $"{_appUrl}/1",
ContentUrl = $"{_appUrl}/1",
RemoveUrl = null
}
});
就像我提到的那样,这只是一种解决方法。它在 GitHub (issue#598)
上标记为 "service bug"
上下文:
我正在尝试向 MS Teams 中的现有频道添加一个新的网站选项卡,然后获取新创建的选项卡的 ID。
问题:
我可以创建新选项卡,但我从图表中收到 "BadRequest" 异常:
消息:值不能为空。参数名称:entity
有趣的是,该选项卡是在正确的团队和频道中的 MS Teams 中创建并显示的,但我无法以任何方式获取它的 ID。
我的代码:
var tab = await _graphClient.Teams[teamId].Channels[channelId].Tabs.Request().WithMaxRetry(3).AddAsync(
new TeamsTab
{
DisplayName = "New Tab",
AdditionalData = new Dictionary<string, object>
{
["teamsApp@odata.bind"] =
$"{_teamsFactory.GraphV1Endpoint}/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web"
},
Configuration = new TeamsTabConfiguration
{
EntityId = null,
WebsiteUrl = $"{_appUrl}/1",
ContentUrl = $"{_appUrl}/1",
RemoveUrl = null,
}
}
);
就像我在上面写的那样,此代码有效并创建了选项卡,但 GraphServiceClient 在分配 tab 变量之前抛出异常。
当我尝试在 Graph Explorer 中获取选项卡列表时
https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channelid}/tabs
我收到错误回复:
{
"error": {
"code": "InternalServerError",
"message": "Failed to execute request.",
"innerError": {
"request-id": "a03654e8-37a7-4fbb-8052-6a1b11721234",
"date": "2020-02-24T15:11:54"
}
}
}
我认为您可能需要为 "EntityId" 设置一个值 - 基本上只是一个字符串值,以唯一地 "name" 您的选项卡。它不是 "DisplayName",而是选项卡的字符串 "id"。
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/tabs
{
"displayName": "My Contoso Tab",
"teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
"configuration": {
"entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
"contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
"websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
"removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
}
}
请看Add Tab to a channel using Graph API
编辑 1:能否请您检查一下您是否具有添加选项卡的适当权限?
Edit2:你能试试下面的代码吗?
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var teamsTab = new TeamsTab
{
DisplayName = "WebsiteTab",
AdditionalData = new Dictionary<string, object>()
{
{"teamsApp@odata.bind","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web"}
},
Configuration = new TeamsTabConfiguration
{
EntityId = null,
ContentUrl = "https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-context",
RemoveUrl = null,
WebsiteUrl = "https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-context"
}
};
await graphClient.Teams["TeamId"].Channels["ChannelId"].Tabs
.Request()
.AddAsync(teamsTab);
最后我找到了 "solution",不过更好的名称是解决我的问题的方法。为了让它工作,我必须在 TeamsTabConfiguration
中将 ODataType
设置为 null
。就这样。代码应如下所示:
var tab = await _graphClient.Teams[teamId].Channels[channelId].Tabs.Request().WithMaxRetry(3).AddAsync(
new TeamsTab
{
DisplayName = TabTitle,
ODataBind = $"{_teamsFactory.GraphV1Endpoint}/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web",
Configuration = new TeamsTabConfiguration
{
ODataType = null,
EntityId = null,
WebsiteUrl = $"{_appUrl}/1",
ContentUrl = $"{_appUrl}/1",
RemoveUrl = null
}
});
就像我提到的那样,这只是一种解决方法。它在 GitHub (issue#598)
上标记为 "service bug"