{"id":34202,"date":"2017-11-28T10:07:20","date_gmt":"2017-11-28T18:07:20","guid":{"rendered":"https:\/\/blog.xamarin.com\/?p=34202"},"modified":"2017-11-28T10:07:20","modified_gmt":"2017-11-28T18:07:20","slug":"lets-schedule-meeting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/lets-schedule-meeting\/","title":{"rendered":"Schedule Meetings with Xamarin.Forms and the Microsoft Graph API"},"content":{"rendered":"<p>\t\t\t\tMeetings can be productive,\u00a0provided they&#8217;re planned and scheduled properly. There are numerous tools available to schedule meetings, with Calendar for Outlook\u00a0being one of the best tools in this category.<\/p>\n<p>To learn how to create a mobile meeting planner app, you can use Xamarin.Forms and the Microsoft Graph API. Xamarin.Forms ensures that the app will run on Android, iOS, and Windows, while the Microsoft Graph API ensures that the app can communicate with Outlook.com (Microsoft Account) or Office 365 (Enterprise Account).<\/p>\n<h2>Register the Application<\/h2>\n<p>The first step in creating an app that has access to personal information is to register it with the required service. This can be accomplished by <a href=\"https:\/\/apps.dev.microsoft.com\/\">signing into the Application Registration Portal<\/a>, clicking the &#8216;Add an app&#8217; button, and completing the required workflow. You can find a previously documented &#8216;Leave&#8217; application app in this <a href=\"https:\/\/blog.xamarin.com\/enterprise-apps-made-easy-updated-libraries-apis\/\">blog sample<\/a>.\u00a0Note that you must add delegated permissions for\u00a0<code>\"User.Read\"<\/code>, <code>\"Calendars.Read\"<\/code>, <code>\"Calendars.ReadWrite\"<\/code>.\u00a0Once app registration is complete, make a note of the Client iD and URLs.<\/p>\n<h2>Displaying Meetings<\/h2>\n<p>When the\u00a0user authenticates, a list of the last five meetings can be displayed on the page. The following XAML code example shows how this can be accomplished using a ListView:<\/p>\n<pre><code>\n    \n        \n            <Label \/>\n            \n                \n                    \n                        \n                    \n                \n            \n        \n    \n\n<\/pre>\n<p><\/code>\nThe <code>OnAppearing()<\/code> override is executed when the page appears, as shown in the following code example:<\/p>\n<pre class=\"EnlighterJSRAW\">protected async override void OnAppearing()\n{\n   base.OnAppearing();\n   WelcomeText.Text = $\"Welcome {((User)App.Me).DisplayName}, your latest meetings:\";\n   var client = new GraphServiceClient(\"https:\/\/graph.microsoft.com\/v1.0\",\n      new DelegateAuthenticationProvider(\n      async (requestMessage) =&gt;\n      {\n         var tokenRequest = await App.IdentityClientApp.AcquireTokenSilentAsync(App.Scopes, App.IdentityClientApp.Users.FirstOrDefault());\n         requestMessage.Headers.Authorization = new AuthenticationHeaderValue(\"bearer\", tokenRequest.AccessToken);\n      })); \n   var events = await client.Me.Events.Request().GetAsync();\n   var list = events.ToList();\n   MeetingsListView.ItemsSource = list.Take(5);\n}<\/pre>\n<h2>Creating Meetings<\/h2>\n<p>As well as displaying meetings, a mobile meeting app must be able to schedule meetings. This can be accomplished by using the <code>DatePicker<\/code> and <code>TimePicker<\/code> controls from Xamarin.Forms to set the meeting date and time. The following XAML code example shows a basic form for scheduling a meeting:<\/p>\n<pre><code>\n    \n        \n            \n            \n            \n            \n            \n            \n            \n            \n            \n            \n            \n        \n    \n    \n        \n    \n<\/pre>\n<p><\/code>\nWhen the toolbar button is clicked, the following code is executed:<\/p>\n<pre class=\"EnlighterJSRAW\">private async void MenuItem_OnClicked(object sender, EventArgs e)\n {\n var calEvent = new Event\n {\n Subject = Subject.Text,\n Start = new DateTimeTimeZone\n {\n DateTime = StartDate.Date.Add(StartTime.Time).ToString(\"yyyy-MM-ddTHH:mm:ss\"),\n TimeZone = \"Asia\/Kolkata\"\n },\n End = new DateTimeTimeZone()\n {\n DateTime = EndDate.Date.Add(EndTime.Time).ToString(\"yyyy-MM-ddTHH:mm:ss\"),\n TimeZone = \"Asia\/Kolkata\"\n },\n Location = new Location() {DisplayName = Location.Text},\n Attendees = new List\n {\n new Attendee() {EmailAddress = new EmailAddress() {Address = Attendee.Text}},\n }\n };\n var client = new GraphServiceClient(\"https:\/\/graph.microsoft.com\/v1.0\",\n new DelegateAuthenticationProvider(\n async (requestMessage) =&gt;\n {\n var tokenRequest = await App.IdentityClientApp.AcquireTokenSilentAsync(App.Scopes, App.IdentityClientApp.Users.FirstOrDefault());\n requestMessage.Headers.Authorization = new AuthenticationHeaderValue(\"bearer\", tokenRequest.AccessToken);\n }));\n await client.Me.Events.Request().AddAsync(calEvent);\n await DisplayAlert(\"Event added\", \"Calendar invite added and sent to attendees\", \"Ok\");\n }<\/pre>\n<h3>The App<\/h3>\n<p>Once your code is complete, you can run the app and schedule meetings!<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-34207\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Graph-API-Events.gif\" alt=\"\" width=\"1920\" height=\"1080\" \/><\/p>\n<h3>Wrapping Up<\/h3>\n<p>The Microsoft Graph APIs allow you to send email and schedule meetings using unified app registration, among other functionality. Xamarin.Forms can consume these APIs, making it possible to build cross-platform apps to schedule meetings. You can find the sample used in this blog post on <a href=\"https:\/\/github.com\/mayur-tendulkar\/\">GitHub<\/a><\/p>\n<p><a href=\"https:\/\/forums.xamarin.com\/109031\/schedule-meetings-with-xamarin-forms-and-the-microsoft-graph-api\/\">Discuss this post on the forums!<\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Meetings can be productive,\u00a0provided they&#8217;re planned and scheduled properly. There are numerous tools available to schedule meetings, with Calendar for Outlook\u00a0being one of the best tools in this category. To learn how to create a mobile meeting planner app, you can use Xamarin.Forms and the Microsoft Graph API. Xamarin.Forms ensures that the app will run [&hellip;]<\/p>\n","protected":false},"author":549,"featured_media":34204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4,16],"class_list":["post-34202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform","tag-xamarin-forms"],"acf":[],"blog_post_summary":"<p>Meetings can be productive,\u00a0provided they&#8217;re planned and scheduled properly. There are numerous tools available to schedule meetings, with Calendar for Outlook\u00a0being one of the best tools in this category. To learn how to create a mobile meeting planner app, you can use Xamarin.Forms and the Microsoft Graph API. Xamarin.Forms ensures that the app will run [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/34202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/549"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=34202"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/34202\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=34202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=34202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=34202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}