以编程方式将 SharePoint 库团队选项卡添加到 Microsoft 团队频道

Programmatically adding SharePoint Library Teams Tab to Microsoft Teams Channel

我正在尝试通过 Microsoft Graph 以编程方式将 SharePoint Library 选项卡添加到 Microsoft Team Channel。 这是我通过 Graph Explorer POST

发送的有效负载
{
    "teamsAppId": "com.microsoft.teamspace.tab.files.sharepoint",
    "name": "Documents3",
    "sortOrderIndex": "10300",
    "configuration": {
        "siteUrl": "https://baywet.sharepoint.com/sites/customerhub",
        "libraryServerRelativeUrl": "/sites/customerhub/Shared Documents",
        "selectedDocumentLibraryTitle": "Documents",
        "selectedSiteTitle": "customerhub",
        "dateAdded": "2018-10-05T16:56:59.169Z"
    }
}

我收到 201 状态响应,我的选项卡已添加到频道。 然而,每当有人尝试从 Teams UI 上传文件时,他们都会收到以下错误消息 The File {filename} is missing。如果他们点击 Open in SharePoint 然后上传文件,就可以了。

如果我与通过 UI 创建的选项卡(正常工作)进行比较,这里是我得到的描述。

{
    "id": "a68e34db-9d43-4821-953b-2dec938ce785",
    "name": "Document%20Library",
    "teamsAppId": "com.microsoft.teamspace.tab.files.sharepoint",
    "sortOrderIndex": "10200",
    "webUrl": "https://teams.microsoft.com/l/channel/19%3ab2e05a0aae42487485b13e088d5d2f0f%40thread.skype/tab%3a%3aa63916e6-f252-477d-9696-7934980e7e47?label=Document%2520Library&groupId=71ed6a2e-67ca-4930-a3c2-abb25ca29fbf&tenantId=bd4c6c31-c49c-4ab6-a0aa-742e07c20232",
    "configuration": {
        "entityId": null,
        "contentUrl": null,
        "removeUrl": null,
        "websiteUrl": null,
        "siteUrl": "https://baywet.sharepoint.com/sites/customerhub",
        "libraryServerRelativeUrl": "/sites/customerhub/Shared Documents",
        "libraryId": "706FAD5678484E7B93B0855E52A0BCD9",
        "selectedDocumentLibraryTitle": "Documents",
        "selectedSiteImageUrl": "https://baywet.sharepoint.com/sites/customerhub/_api/GroupService/GetGroupImage?id='f9d430ca-4de3-42f1-9474-1427bfdb16b0'&hash=636743460492415245",
        "selectedSiteTitle": "customerhub",
        "dateAdded": "2018-10-05T16:56:59.169Z"
    }
}

唯一的区别是 libraryId 配置值。 (您不应该发送 webUrl 和 id)。 此库 ID 与 SharePoint 中的库 ID 或图表中的驱动器项目 ID 不匹配,因此我的问题是:我应该为 libraryId 设置什么值? 我还有什么遗漏的吗?

以下代码为已知组 ID(365,创建时创建了一个团队站点)创建团队,并在现有频道上添加 3 个选项卡。

          IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                                 .Create(GraphClientId)
                                 .WithTenantId(GraphTenantId)
                                 .WithClientSecret(GraphClientSecret)
                                 .Build();
            ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
            GraphServiceClient graphClient = new GraphServiceClient(authProvider);

            var team = new Team
            {
                MemberSettings = new TeamMemberSettings
                {
                    AllowCreateUpdateChannels = true
                },
                MessagingSettings = new TeamMessagingSettings
                {
                    AllowUserEditMessages = true,
                    AllowUserDeleteMessages = true
                },
                FunSettings = new TeamFunSettings
                {
                    AllowGiphy = true,
                    GiphyContentRating = GiphyRatingType.Moderate
                }
            };

            Team addedTeam = await graphClient.Groups[GroupID].Team
                .Request()
                .PutAsync(team);

            ECGTeam ecgTeam = new ECGTeam {ProjectNumber= ProjectNumber ,GroupID = GroupID, TeamID = addedTeam.Id };

            string channelID = string.Empty;
            var channels = await graphClient.Teams[addedTeam.Id].Channels.Request().GetAsync();
            channelID = channels[0].Id;
            ecgTeam.ChannelID = channelID;

            TeamsTab newTab = addTab(targetWebUrl, "WorkingPapers", "Working Papers");
            var addedTab = await graphClient.Teams[addedTeam.Id].Channels[channelID].Tabs.Request().AddAsync(newTab);
            ecgTeam.TabWorkingPapersID = addedTab.Id;
            //DPC documents
            newTab = addTab(targetWebUrl, "DPCdocuments", "DPC documents");
            addedTab = await graphClient.Teams[addedTeam.Id].Channels[channelID].Tabs.Request().AddAsync(newTab);
            ecgTeam.TabDPCdocumentsID=addedTab.Id;
            //ContractDocuments //
            newTab = addTab(targetWebUrl, "ContractDocuments", "Contract Documents");
            addedTab = await graphClient.Teams[addedTeam.Id].Channels[channelID].Tabs.Request().AddAsync(newTab);
            ecgTeam.TabContractDocumentsID = addedTab.Id;
            //log.LogInformation(addedTab.Id);

现在,如果你能帮我为上述网站创建一个使用自定义内容类型的图书馆,我会请你喝咖啡:-) .NET Core 中 MS Graph 的丰富文档让我想哭:-(

一段时间后我找到了解决方案,很抱歉没有早点在这里发布。

POST https://graph.microsoft.com/beta/teams/{groupId}/channels/{channelId}/tabs

{
    "teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/com.microsoft.teamspace.tab.files.sharepoint",
    "name": "test",
    "sortOrderIndex": "10400",
    "configuration": {
        "contentUrl": "https://baywet.sharepoint.com/sites/NYC/test"
    }
}

其中 contentUrl 是文档库URL