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