C# 使用MS Graph添加团队频道

C# 使用MS Graph添加团队频道,c#,microsoft-graph-api,botframework,microsoft-teams,C#,Microsoft Graph Api,Botframework,Microsoft Teams,我正在尝试在bot框架内使用MS-Graph创建一个通道。我得到了一个有效的访问令牌。但是,下面的代码会生成以下错误: 不支持“Microsoft.Graph.Channel.Members”上的集合类型“Microsoft.Graph.IChannelMembersCollectionPage” var credential = new DefaultAzureCredential(); var token = credential.GetToken( new Azure.Core.T

我正在尝试在bot框架内使用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 portal中提供应用程序权限,并使用以下代码在MS团队中创建频道。下面是您需要安装的软件包

这是应用程序权限的示例。您可以尝试相同的代码,对委派权限进行细微更改/不更改


您是否在或POSTMAN中测试过它,它是否按预期工作?是的,我能够使用Graph Explorer在这个团队中创建频道。但是,这将基于我的凭据创建频道。我已为托管bot的Web应用程序启用以下代理权限:Channel.Create Channel.Delete.All Channel.ReadBasic.All openid profile User.ReadNo Joy。我有一个新的,非常没有帮助的异常:未知错误内部错误:附加数据:日期:2021-01-25T19:47:32请求id:ebc7b3f9-f553-4583-b239-5eaee8caa0d0客户端请求id:ebc7b3f9-f553-4583-b239-5eaee8caa0d0客户端id:ebc7b3f9-f553-4583-b239-5eaee8caa0d0关于如何调试这样的错误有什么建议吗?@RichH:我们可以通过呼叫连接到讨论这个?请写信给我们microsoftteamsdev@microsoft.com
           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);