【问题标题】:Programmatically adding SharePoint Library Teams Tab to Microsoft Teams Channel以编程方式将 SharePoint 库团队选项卡添加到 Microsoft 团队频道
【发布时间】:2019-03-11 08:24:24
【问题描述】:

我正在尝试通过 Microsoft Graph 以编程方式将 SharePoint Library 选项卡添加到 Microsoft 团队频道。 这是我通过 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 设置什么值我还有什么遗漏的吗?

【问题讨论】:

  • 我想让你知道我们正在调查这个问题,一旦我们弄清楚了就会通知你。

标签: microsoft-graph-api microsoft-teams


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    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

    【讨论】:

      猜你喜欢
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      相关资源
      最近更新 更多