question

AlwinJames-2372 avatar image
0 Votes"
AlwinJames-2372 asked

An error getting when i try to send a message to microsoft teams channel by using Graph API

Hi team,

I have created a console application in .NET core. I have installed Microsoft Graph into this application by using NuGet Packet manager. I got an error ("UnAuthorized") when I try to send a message to Microsoft teams channel . I mentioned by sample code below,

AzureGraphAuthConfig config = AzureGraphAuthConfig.ReadFromJsonFile("appsettings.json");
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(config.GraphClientId)
.WithTenantId(config.GraphTenant)
.WithClientSecret(config.GraphClientSecret)
.Build();

             ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
             graphClient = new GraphServiceClient(authProvider);


             var chatMessage = new ChatMessage
             {
                 Body = new ItemBody
                 {
                     Content = "Hello Team"
                 }
             };

             var res = await graphClient.Teams[teamId].Channels[channelId].Messages.Request().AddAsync(chatMessage);



Getting an error When I execute this code. But working fine from Graph explorer.
Could you please suggest a proper solution for this?

THANKS

microsoft-graph-teamwork
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers