Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用图形API错误添加MS团队网站选项卡_C#_Tabs_Microsoft Graph Api_Microsoft Teams - Fatal编程技术网

C# 使用图形API错误添加MS团队网站选项卡

C# 使用图形API错误添加MS团队网站选项卡,c#,tabs,microsoft-graph-api,microsoft-teams,C#,Tabs,Microsoft Graph Api,Microsoft Teams,上下文: var tab = await _graphClient.Teams[teamId].Channels[channelId].Tabs.Request().WithMaxRetry(3).AddAsync( new TeamsTab { DisplayName = "New Tab", AdditionalData = new Dictionary<string, object> { [

上下文:

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,

        }
    }
);
我正在尝试向MS团队中的现有频道添加一个新的网站选项卡,然后获取新创建的选项卡的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,

        }
    }
);
我可以创建新选项卡,但我从图表中得到一个“BadRequest”异常:

消息:值不能为空。参数名称:实体

有趣的是,该选项卡在MS团队中以正确的团队和渠道创建并可见,但我无法以任何方式获取其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,

        }
    }
);

我认为您可能需要为“EntityId”设置一个值——基本上只是一个字符串值,用于唯一地“命名”选项卡。它不是“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"
  }
}
请看一看

编辑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); 
GraphServiceClient-graphClient=新的GraphServiceClient(authProvider);
var teamsTab=新teamsTab
{
DisplayName=“WebsiteTab”,
AdditionalData=新字典()
{
{"teamsApp@odata.bind","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/com.microsoft.teamspace.tab.web"}
},
配置=新的TeamsTabConfiguration
{
EntityId=null,
ContentUrl=”https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-context",
RemoveUrl=null,
网站URL=”https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-context"
}
};
等待graphClient.Teams[“TeamId”]。Channels[“ChannelId”]。选项卡
.Request()
.AddAsync(teamsTab);
我终于找到了“解决方案”,尽管更好的名称是解决我的问题的一个方法。为了让它工作,我必须在
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()上被标记为“服务bug”

我以前试过这个,但没有用。根据MS文档(网站选项卡部分),EntityId属性应该设置为null。哦,是的,我明白你的意思了-我在考虑定制应用程序。请看这里:。在底部的评论中,它看起来可能[”teamsApp@odata.bind“]=$”\u teamsFactory.GraphV1Endpoint}/appCatalogs/teamsaps/com.microsoft.teamspace.tab.web“实际上应该是普通的[”teamsApp@odata.bind“]=“com.microsoft.teamspace.tab.web”抱歉,它不起作用。我收到“在@odata.bind for teamsApp中指定的URL格式无效”错误消息。我正在尝试添加网站选项卡。根据TeamSapID为“com.microsoft.teamspace.tab.web”,entityId属性应设置为null。当您将实体id设置为null时,该属性正在工作,您是否可以共享更多详细信息,或者复制步骤或屏幕录制更适合进一步调查?@Tomasz,您是否仍面临此问题?很遗憾,是的。我将entityId属性设置为null(正如您在问题描述中我共享的代码部分中所看到的那样),它一直工作到创建选项卡的时候。然后代码抛出一个异常,消息为“Value不能为null。Parameter name:entity”,我无法获取已创建选项卡的id。请重新返回以microsoftteamsdev@microsoft.com因此,我们可以调试并查看问题。