提问人:Yogesh Shinde 提问时间:11/17/2023 更新时间:11/17/2023 访问量:33
C 语言中的 MS Teams 会议集成#
MS Teams Meeting integration in C#
问:
我正在尝试在 C# 中创建一个能够与 Microsoft 团队集成的应用程序,我可以在其中安排团队会议、获取会议列表和更新,但在创建 MS Teams 会议时,我收到以下错误。
'代码:BadRequest
消息:/me 请求仅对委托的身份验证流有效。
使用以下代码创建 MS Teams 会议
string clientId = "";
string clientSecret = "";
string tenantId = "";
string redirectUri = "";
string authority = $"https://login.microsoftonline.com/{tenantId}";
////string authority = $"https://login.microsoftonline.com/{tenantId}";
// Create a confidential client application
var confidentialClientApp = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
// Define the scopes required for Microsoft Graph API
////string[] scopes = { "User.Read", "OnlineMeetings.ReadWrite" }; // Add any additional scopes needed
var scopes = new string[] { "https://graph.microsoft.com/.default" };
try
{
// Acquire an access token
var result = await confidentialClientApp
.AcquireTokenForClient(scopes)
.ExecuteAsync();
// Use the access token in your Graph API requests
string accessToken = result.AccessToken;
// Create a GraphServiceClient
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
}));
// Create an online meeting
var onlineMeeting = new OnlineMeeting
{
StartDateTime = DateTimeOffset.UtcNow.AddMinutes(5), // Schedule the meeting 5 minutes from now
EndDateTime = DateTimeOffset.UtcNow.AddHours(1), // Set the duration of the meeting (1 hour in this example)
Subject = "Teams Meeting created via Graph API",
};
var createdMeeting = await graphServiceClient.Me.OnlineMeetings
.Request()
.AddAsync(onlineMeeting);
Console.WriteLine($"Meeting created with ID: {createdMeeting.Id}");
Console.WriteLine($"Join URL: {createdMeeting.JoinWebUrl}");
}
catch (Exception ex)
{
Console.WriteLine($"Error acquiring token or making Graph API request: {ex.Message}");
}
答: 暂无答案
评论