I'm creating an Application in C# to integrate with MS Teams. I was able to generate access token but getting error below when attempt to create a meeting using HttpClient() to Post to
"{"error":{"code":"BadRequest","message":"/me request is only valid with delegated authentication flow.",*
Am I missing something with the permission or the code is not correct? Thought?
generate access token code
var confidentialClientApp = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri($"/{tenantId}"))
.Build();
var scopes = new[] { $"/.default" };
var authResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();
accessToken = authResult.AccessToken;
here is create meeting code
var meetingObject = new
{
subject = title,
startDateTime = startTime,
endDateTime = endTime,
accessLevel = "everyone",
entryExitAnnouncement= true,
body = new { content = description },
participants = new {
anizier = new {
identity = new {
user = new {
id = "550fae72-d251-43ec-868c-373732c2704f"
}
}
}
}
};
var jsonobj = Newtonsoft.Json.JsonConvert.SerializeObject(meetingObject);
HttpResponseMessage servicerequest = null;
TeamsMeetingEventObj meetingObj = new TeamsMeetingEventObj();
try
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(".0/me/onlineMeetings");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("authorization", "Bearer " + accessToken + "");
var content = new StringContent(jsonobj.ToString(), System.Text.Encoding.UTF8, "application/json");
servicerequest = httpClient.PostAsync(".0/me/onlineMeetings", content).Result;
string response = servicerequest.Content.ReadAsStringAsync().Result;
meetingObj = JsonConvert.DeserializeObject<TeamsMeetingEventObj>(response);
String OnlineTeamLink = meetingObj.join_WebUrl.ToString();
}
}
catch (Exception ex)
{
meetingObj.general_message = "Exception: " + ex.Message;
}