-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleCreateOnlineMeetings.cs
122 lines (96 loc) · 3.21 KB
/
SampleCreateOnlineMeetings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using Microsoft.Graph;
using Microsoft.Identity.Client;
using Microsoft.Graph.Auth;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
/*
*1. Register with Microsoft 365 Developer Program for development environment. Add Sample Data packs
*2. Create App Registration in Azure portal. Copy App ID, and create Client Secret.
*3. Add Graph API permissions depending on API. Also add User.Read, Directory.Read, and then complete Admin Consent
*
*
*
*/
namespace Graph_CreateEventOnline
{
class SampleCreateOnlineMeetings
{
static async System.Threading.Tasks.Task Main(string[] args)
{
//Setup Auth
string clientId = "fd0ae99b-0717-4985-90a2-829f473c9c36";
string tenantID = "c73250cd-044c-4f51-beb8-020d87ee8daa";
string clientSecret = "SfS2_O_jBDvPM-a526EwG_0rn-n5qJ-xSc";
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.WithClientSecret(clientSecret)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
try
{
var @event = new Event
{
Subject = "Meeting with Customer, Customer Name-Omer Amin",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Add Content here"
},
Start = new DateTimeTimeZone
{
DateTime = "2020-09-20T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2020-09-20T14:00:00",
TimeZone = "Pacific Standard Time"
},
Location = new Location
{
DisplayName = "Online"
},
Attendees = new List<Attendee>()
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "omamin@microsoft.com",
Name = "Omer Amin"
},
Type = AttendeeType.Required
}
},
IsOnlineMeeting = true,
OnlineMeetingProvider = OnlineMeetingProviderType.TeamsForBusiness
};
Task<Event> taskEvent = graphClient.Users["AdeleV@barneyteste5.onmicrosoft.com"].Calendar.Events
.Request()
.AddAsync(@event);
Console.WriteLine("Meeting ID - " + taskEvent.Result.Id);
Console.WriteLine("WebLink - " + taskEvent.Result.OnlineMeeting.JoinUrl);
//Sleep for 5 seconds, and then delete the meeting using the meeting ID.
Console.WriteLine("\nSleep for 5 seconds");
Thread.Sleep(5000);
Console.WriteLine("Deleting meeting");
await graphClient.Users["AdeleV@barneyteste5.onmicrosoft.com"].Calendar.Events[taskEvent.Result.Id]
.Request()
.DeleteAsync();
}
catch (ServiceException e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.Error.Code);
Console.WriteLine(e.StackTrace);
throw;
}
//Specify meeting parameters, and then Add to user's calendar. This will return the Teams meeting link in OnlineMeeting.JoinUrl property.
Console.WriteLine("Meeting Deleted");
}
}
}