using Microsoft.Graph; using Microsoft.Graph.Auth; using Microsoft.Identity.Client; using System; using System.Threading.Tasks; using Newtonsoft.Json; namespace GraphTest { class Program { const string clientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; const string tenantId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; const string clientSecret = "XXXXXXX.XXXXXXXXXX.XXXXX.XXXX..XXX"; static void Main(string[] args) { if(args.Length == 0 || args[0] == null || args[0] == "") { Console.WriteLine("Usage: GraphTest.exe [call-id]\r\nPress ender to exit."); } else { try { MainAsync(args[0]).GetAwaiter().GetResult(); } catch (Exception e) { Console.WriteLine("Operation failed: {0}", e); } Console.WriteLine("Done. Press enter to exit."); } Console.ReadLine(); } static async Task MainAsync(String callID) { IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder .Create(clientId) .WithTenantId(tenantId) .WithClientSecret(clientSecret) .Build(); ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication); GraphServiceClient graphClient = new GraphServiceClient(authProvider); Console.WriteLine("Reading call records for call " + callID); var callRecord = await graphClient.Communications.CallRecords[callID] .Request() .GetAsync(); if (callRecord != null) { Console.WriteLine("Found!"); } Console.WriteLine("{0}", JsonConvert.SerializeObject(callRecord, Formatting.Indented)); System.IO.File.WriteAllText("record.json", JsonConvert.SerializeObject(callRecord, Formatting.Indented)); Console.WriteLine("Reading call sessions for call " + callID); var sessions = await graphClient.Communications.CallRecords[callID].Sessions .Request() .GetAsync(); if (sessions != null) { Console.WriteLine("Found " + sessions.Count + " sessions"); } System.IO.File.WriteAllText("sessions.json", JsonConvert.SerializeObject(sessions, Formatting.Indented)); Console.WriteLine("Reading call sessions segments for call " + callID); var segments = await graphClient.Communications.CallRecords[callID].Sessions .Request() .Expand("segments") .GetAsync(); if (sessions != null) { Console.WriteLine("Found " + segments.Count + " segments"); } System.IO.File.WriteAllText("segments.json", JsonConvert.SerializeObject(segments, Formatting.Indented)); if (callRecord.Sessions != null) { Console.WriteLine(callRecord.Sessions.Count); } } } }