以编程方式将SharePoint Library Teams选项卡添加到Microsoft Teams Channel

时间:2018-10-05 19:31:21

标签: microsoft-graph microsoft-teams

我试图通过Microsoft Graph以编程方式向Microsoft Team Channel添加一个SharePoint Library标签。 这是我通过图形资源管理器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,然后上传文件,它将起作用。
teams error message
如果将我与通过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设置什么值还有什么我想念的吗?

2 个答案:

答案 0 :(得分:0)

以下代码为已知的组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的大量优质文档让我想哭:-(

答案 1 :(得分:0)

过一会儿我找到了解决方案,对不起,我没有在这里早些发布。

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