簡體   English   中英

使用 MS Graph 添加團隊頻道

[英]Adding a Teams Channel Using MS Graph

我正在嘗試在 BotFramework 機器人中使用 MS Graph 創建一個通道。 我得到了似乎是有效的訪問令牌。 但是下面的代碼會產生以下錯誤:

不支持“Microsoft.Graph.Channel.Members”上的集合類型“Microsoft.Graph.IChannelMembersCollectionPage”。

var credential = new DefaultAzureCredential();
var token = credential.GetToken(
    new Azure.Core.TokenRequestContext(
        new[] { "https://graph.microsoft.com/.default" }));

var accessToken = token.Token;
Logger.LogWarning($"Token:{accessToken.ToString()}");
var graphServiceClient = new GraphServiceClient(
    new DelegateAuthenticationProvider((requestMessage) =>
    {
        requestMessage
        .Headers
        .Authorization = new AuthenticationHeaderValue("bearer", accessToken);

        return Task.CompletedTask;
    }));


try
{

    var chan = new Channel
    {
        DisplayName = $"Chan1",
        Description = "This channel is where we debate all future world domination plans",
        MembershipType = ChannelMembershipType.Standard
    };


    await graphServiceClient.Teams["{GroupID}"].Channels.Request().AddAsync(chan);
}

您可以使用 Graph SDK 在內部生成令牌。 請嘗試在 azure 門戶中提供應用程序權限,並使用以下代碼在 MS Teams 中創建頻道。 以下是您需要安裝的軟件包。

這是應用程序權限的示例。 您可以嘗試相同的代碼,只需稍作更改/不更改委托權限。

在此處輸入圖像描述

           string clientId = "";
            string clientSecret = "1";
            string tenantId = "";
          
       

            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithTenantId(tenantId)
    .WithClientSecret(clientSecret) // or .WithCertificate(certificate)
    .Build();

            //AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(confidentialClientApplication, scopes);

            ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);


            GraphServiceClient graphClient = new GraphServiceClient(authProvider);

            var channel = new Channel
            {
                DisplayName = "Topic Discussion",
                Description = "This channel is where we debate all future architecture plans",
                MembershipType = ChannelMembershipType.Standard
            };

            await graphClient.Teams["{Your-teams-id}"].Channels
                .Request()
                .AddAsync(channel);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM