Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 12:53, 25 April 2013 by somnathbanik (Talk | contribs)

Birthday Calendar for Windows Phone

From Wiki
Jump to: navigation, search

This article demonstrates how to integrate Facebook friends birthday events to a calendar using Microsoft Live Connect API.

WP Metro Icon UI.png
WP Metro Icon Web.png
WP Metro Icon Tools.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
Devices(s): Nokia Lumia 820,920
Platform(s): Windows Phone
Windows Phone 8
Windows Phone 7.5
Platform Security
Signing Required: Self-Signed
Keywords: Facebook events
Created: somnathbanik (25 Apr 2015)
Last edited: somnathbanik (25 Apr 2013)



Windows Phone Calendar API doesn’t provide access to Facebook events/birthday. So the Facebook events/birthday that we see in the device default calendar can’t be replicated into our apps. To overcome this we will use some tips and tricks, and Microsoft Live Connect SDK to get the Facebook birthday events in our app. If you are new to Live Connect SDK, suggest you to visit Getting user information with the Live Connect API for Windows Phone 7 article for better understanding.

Note.pngNote: To fetch the Facabook birthday events using Live Connect SDK, please make sure your Microsoft account is linked with your Facebook accout.


Create a standard Windows Phone Project

Let’s create a standard Windows Phone Application Project

  • Launch Visual Studio
  • Click on File
  • Click on New Project
  • Select Windows Phone Application (Visual C# Template)
  • Add Name and Location of the project
  • Click OK to create the project.

Adding UI controls on application page

We add a Live SDK SignInButton for login to Microsoft account along with an Image, TextBlock and a Calendar element in MainPage.xaml file.

Note.pngNote: The calendar is created using Telerik RadControls for Windows Phone 8.

  <!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Orientation="Horizontal" Grid.Row="0" Margin="12,0,0,0">
<TextBlock Text="BIRTHDAY CALENDAR" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0,80,0" VerticalAlignment="Top"/>
<live:SignInButton Name="btnSignin" ClientId="Client ID" Branding="Outlook" Scopes="wl.events_create wl.calendars_update wl.basic wl.offline_access wl.signin wl.contacts_birthday wl.calendars" TextType="SignIn" SessionChanged="btnSignin_SessionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" />
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Orientation="Vertical">
<StackPanel Margin="12,0,0,0" Orientation="Horizontal">
<Image Name="userImage" Height="100" Width="100" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<StackPanel Orientation="Vertical" Margin="12,0,0,0">
<TextBlock Name="userGreetings" Text="" Style="{StaticResource PhoneTextNormalStyle}" ></TextBlock>
<TextBlock Name="userName" Text="" FontWeight="Bold" Style="{StaticResource PhoneTextExtraLargeStyle}"></TextBlock>
<StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" >
<telerikInput:RadCalendar SelectedValueChanged="RadCalendar_SelectedValueChanged_1" WeekNumbersVisibility="Visible" Height="450" MonthInfoDisplayMode="Large" VerticalAlignment="Bottom" AppointmentSource="{StaticResource CalendarAppointments}">
<telerikPrimitives:RadDataBoundListBox x:Name="AppointmentsList" Height="129" Margin="-12,8,0,0" EmptyContent="There are no birthday for the selected day.">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="0,0,0,12">
<Rectangle Fill="{StaticResource PhoneAccentBrush}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="8" Height="32" Margin="12,0,12,0"/>
<TextBlock Text="{Binding Subject}" FontWeight="Bold" FontFamily="{StaticResource PhoneFontFamilySemiLight}" FontSize="{StaticResource PhoneFontSizeSmall}" Margin="0, -3, 0, -3"/>

Adding code behind

  • Add the following List class to store Facebook birthday events.
   public static class BirthdayData
public static List<BirthdayStructure> ListBirthdayData = new List<BirthdayStructure>();
public static string BirthdayCalendarId = null;
public class BirthdayStructure
public string id { get; set; }
public string name { get; set; }
public string start_time { get; set; }
public string end_time { get; set; }
  • Add the following code to create a Live Session and get user information and profile picture.
  // create a session
LiveSession.client = new LiveConnectClient(e.Session);
LiveSession.Session = e.Session;
// get user info
LiveOperationResult operationResultMe = await LiveSession.client.GetAsync("me");
dynamic resultMe = operationResultMe.Result;
//get user profile picture
LiveOperationResult operationResultPicture = await LiveSession.client.GetAsync("me/picture");
dynamic resultPicture = operationResultPicture.Result;
dynamic meResult = operationResultMe.Result;
if (meResult.first_name != null &&
meResult.last_name != null)
userGreetings.Text = "Hello";
userName.Text = meResult.first_name + " " + meResult.last_name + "!";
userImage.Source = new BitmapImage(new Uri(resultPicture.location, UriKind.RelativeOrAbsolute));
userGreetings.Text = "Hello, sign in successful!";
catch (LiveConnectException exception)
userGreetings.Text = "API Error : " +
  • Add the following code to get the user’s calendars id. This code will get all the calendar id added to the use’s account.
                   LiveConnectClient liveClientCal = new LiveConnectClient(LiveSession.session);
LiveOperationResult operationResultCal = await liveClientCal.GetAsync("me/calendars");
dynamic resultCal = operationResultCal.Result;
List<object> dataCal = (List<object>)operationResultCal.Result["data"];
  • Add the following code to check the existence of user’s Birthday calendar and get the next 30 days birthday event details and add it to calendar.
                     if (tempCalName == "Birthday calendar")
BirthdayData.BirthdayCalendarId = (string)calInfo["id"];
LiveConnectClient liveClient = new LiveConnectClient(LiveSession.session);
LiveOperationResult operationResult = await liveClient.GetAsync(BirthdayData.BirthdayCalendarId + "/events");
dynamic result = operationResult.Result;
List<object> data = (List<object>)operationResult.Result["data"];
foreach (IDictionary<string, object> bdayInfo in data)
string tempTime = "00:00:00";
BirthdayStructure bdayData = new BirthdayStructure(); = (string)bdayInfo["id"]; = (string)bdayInfo["name"];
string tempStartTime = (string)bdayInfo["start_time"];
string[] splitStartTime = tempStartTime.Split(new Char[] { 'T' });
bdayData.start_time = splitStartTime.GetValue(0).ToString()+" "+tempTime;
string tempEndTime = (string)bdayInfo["end_time"];
string[] splitEndTime = tempEndTime.Split(new Char[] { 'T' });
bdayData.end_time = splitEndTime.GetValue(0).ToString()+" "+tempTime;
  • Add the following code to display the birthday events of a selected date on the calendar.
private void DisplayAppointmentsForDate(DateTime date)
appointmentsSource.FetchData(date, date.AddDays(1));
this.AppointmentsList.ItemsSource = appointmentsSource.GetAppointments((IAppointment appointment) =>
DateTime startDate = appointment.StartDate;
DateTime endDate = appointment.EndDate;
DateTime calendarStartDate = date.Date;
DateTime calendarEndDate = date.AddDays(1);
if (calendarStartDate == startDate && calendarEndDate == endDate)
return true;
return false;
//display all the birthday of a selected date
private void RadCalendar_SelectedValueChanged_1(object sender, ValueChangedEventArgs<object> e)
if (e.NewValue == null)
this.AppointmentsList.ItemsSource = null;
DisplayAppointmentsForDate((e.NewValue as DateTime?).Value);


This example uses the trial version of Telerik RadControls for Windows Phone 8, for production purpose please download the license copy. Most of the code are called from a PhoneClassLibrary which is a part of the project reference. Please download the source code for better understanding of the code flow.

Source Code

250 page views in the last 30 days.