×
Namespaces

Variants
Actions
(Difference between revisions)

Birthday Calendar for Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search
somnathbanik (Talk | contribs)
(Somnathbanik - - Adding UI controls on application page)
hamishwillee (Talk | contribs)
m (Hamishwillee -)
 
(21 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Draft]]
+
[[Category:Web Services on Windows Phone]][[Category:Telerik RadControls]][[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:XAML]][[Category:Code Examples]]
 
{{Abstract| This article demonstrates how to integrate Facebook friends birthday events to a calendar using [http://msdn.microsoft.com/en-us/library/live/ff621314.aspx Microsoft Live Connect API].}}
 
{{Abstract| This article demonstrates how to integrate Facebook friends birthday events to a calendar using [http://msdn.microsoft.com/en-us/library/live/ff621314.aspx Microsoft Live Connect API].}}
  
{{ArticleMetaData <!-- v1.2 -->
+
{{ArticleMetaData <!-- v1.3 -->
|sourcecode= [[Media: BirthdayCalendar.zip]]<!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode= [[Media:BirthdayCalendar.zip]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Nokia Lumia 820,920 <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|devices= Nokia Lumia 820,920 <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
|sdk== [http://www.microsoft.com/en-us/download/details.aspx?id=35471 Windows Phone SDK 8.0] <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
+
|sdk= [http://www.microsoft.com/en-us/download/details.aspx?id=35471 Windows Phone SDK 8.0] <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
|platform= Windows Phone<!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
+
|platform= Windows Phone 7.5 and later
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->  
+
|signing= Self-Signed<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
|signing=Self-Signed<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|capabilities= ID_CAP_APPOINTMENTS, ID_CAP_CONTACTS<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|capabilities=ID_CAP_APPOINTMENTS, ID_CAP_CONTACTS<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
+
 
|keywords= Facebook events<!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|keywords= Facebook events<!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|creationdate=25th April, 2013 <!-- Format YYYYMMDD -->
+
|creationdate= 25th April, 2013 <!-- Format YYYYMMDD -->
|author=[[User: somnathbanik]] <!-- Display as link [[User:username]] -->
+
|author= [[User:Somnathbanik]]
 +
<!-- The following are not in current metadata -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
}}
 
}}
  
 
==Introduction==
 
==Introduction==
[http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207071%28v=vs.105%29.aspx 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 [http://msdn.microsoft.com/en-us/library/live/ff621314.aspx 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.  
+
[http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207071%28v=vs.105%29.aspx 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 [http://msdn.microsoft.com/en-us/library/live/ff621314.aspx 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| To fetch the Facabook birthday events using Live Connect SDK, please make sure your Microsoft account is linked with your Facebook accout. }}
+
{{Note| To fetch the Facabook birthday events using Live Connect SDK, please make sure your Microsoft account is linked with your Facebook account. }}
 
<gallery widths=180px heights=300px>
 
<gallery widths=180px heights=300px>
 
File: wp_ss_20130425_0001.png| Microsoft Account login
 
File: wp_ss_20130425_0001.png| Microsoft Account login
Line 35: Line 36:
  
 
== Implementation==
 
== Implementation==
 
 
===Create a standard Windows Phone Project===
 
===Create a standard Windows Phone Project===
 
Let’s create a standard Windows Phone Application Project
 
Let’s create a standard Windows Phone Application Project
Line 65: Line 65:
 
             </StackPanel>
 
             </StackPanel>
 
                 <StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" >
 
                 <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}">                         
+
                     <telerikInput:RadCalendar SelectedValueChanged="RadCalendar_SelectedValueChanged_1" WeekNumbersVisibility="Visible" Height="450"  MonthInfoDisplayMode="Large" VerticalAlignment="Bottom" AppointmentSource="{StaticResource CalendarAppointments}">                         
 
                     </telerikInput:RadCalendar>
 
                     </telerikInput:RadCalendar>
 
                     <telerikPrimitives:RadDataBoundListBox x:Name="AppointmentsList" Height="129" Margin="-12,8,0,0" EmptyContent="There are no birthday for the selected day.">
 
                     <telerikPrimitives:RadDataBoundListBox x:Name="AppointmentsList" Height="129" Margin="-12,8,0,0" EmptyContent="There are no birthday for the selected day.">
Line 83: Line 83:
 
         </Grid>
 
         </Grid>
 
</code>
 
</code>
 
+
===Adding code behind===
 
* Add the following List class to store Facebook birthday events.
 
* Add the following List class to store Facebook birthday events.
 
<code csharp>
 
<code csharp>
  public static class BirthdayData
+
public static class BirthdayData
    {
+
{
 
       public static List<BirthdayStructure> ListBirthdayData = new List<BirthdayStructure>();
 
       public static List<BirthdayStructure> ListBirthdayData = new List<BirthdayStructure>();
 
       public static string BirthdayCalendarId = null;
 
       public static string BirthdayCalendarId = null;
    }
+
}
  public class BirthdayStructure
+
public class BirthdayStructure
    {
+
{
        public string id { get; set; }
+
      public string id { get; set; }
        public string name { get; set; }
+
      public string name { get; set; }
        public string start_time { get; set; }
+
      public string start_time { get; set; }
        public string end_time { get; set; }
+
      public string end_time { get; set; }
    }
+
}
 
</code>
 
</code>
  
Line 103: Line 103:
 
<code csharp>
 
<code csharp>
 
   // create a session
 
   // create a session
              LiveSession.client = new LiveConnectClient(e.Session);
+
                LiveSession.client = new LiveConnectClient(e.Session);
              LiveSession.Session = e.Session;
+
                LiveSession.Session = e.Session;
 
                 // get user info
 
                 // get user info
 
               LiveOperationResult operationResultMe = await LiveSession.client.GetAsync("me");
 
               LiveOperationResult operationResultMe = await LiveSession.client.GetAsync("me");
Line 111: Line 111:
 
               LiveOperationResult operationResultPicture = await LiveSession.client.GetAsync("me/picture");
 
               LiveOperationResult operationResultPicture = await LiveSession.client.GetAsync("me/picture");
 
               dynamic resultPicture = operationResultPicture.Result;
 
               dynamic resultPicture = operationResultPicture.Result;
    try
+
              try
 
               {
 
               {
 
                   dynamic meResult = operationResultMe.Result;
 
                   dynamic meResult = operationResultMe.Result;
Line 135: Line 135:
 
* 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.  
 
* 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.  
 
<code csharp>
 
<code csharp>
                  LiveConnectClient liveClientCal = new LiveConnectClient(LiveSession.session);
+
        LiveConnectClient liveClientCal = new LiveConnectClient(LiveSession.session);
                  LiveOperationResult operationResultCal = await liveClientCal.GetAsync("me/calendars");
+
        LiveOperationResult operationResultCal = await liveClientCal.GetAsync("me/calendars");
                  dynamic resultCal = operationResultCal.Result;
+
        dynamic resultCal = operationResultCal.Result;
                  List<object> dataCal = (List<object>)operationResultCal.Result["data"];
+
        List<object> dataCal = (List<object>)operationResultCal.Result["data"];
 
</code>
 
</code>
  
Line 144: Line 144:
 
<code csharp>
 
<code csharp>
 
if (tempCalName == "Birthday calendar")
 
if (tempCalName == "Birthday calendar")
                      {
+
{
 
                           BirthdayData.BirthdayCalendarId = (string)calInfo["id"];
 
                           BirthdayData.BirthdayCalendarId = (string)calInfo["id"];
 
                           LiveConnectClient liveClient = new LiveConnectClient(LiveSession.session);
 
                           LiveConnectClient liveClient = new LiveConnectClient(LiveSession.session);
Line 165: Line 165:
 
                               BirthdayData.ListBirthdayData.Add(bdayData);
 
                               BirthdayData.ListBirthdayData.Add(bdayData);
 
                           }
 
                           }
                      }
+
}
 
</code>
 
</code>
  
Line 171: Line 171:
 
<code csharp>
 
<code csharp>
 
private void DisplayAppointmentsForDate(DateTime date)
 
private void DisplayAppointmentsForDate(DateTime date)
        {
+
{
 
             appointmentsSource.FetchData(date, date.AddDays(1));
 
             appointmentsSource.FetchData(date, date.AddDays(1));
 
             this.AppointmentsList.ItemsSource = appointmentsSource.GetAppointments((IAppointment appointment) =>
 
             this.AppointmentsList.ItemsSource = appointmentsSource.GetAppointments((IAppointment appointment) =>
Line 193: Line 193:
 
             }
 
             }
 
             DisplayAppointmentsForDate((e.NewValue as DateTime?).Value);
 
             DisplayAppointmentsForDate((e.NewValue as DateTime?).Value);
        }
+
}
 
</code>
 
</code>
  
 
==Summary==
 
==Summary==
This example uses the trial version of Telerik SDK, 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.
+
This example uses the [http://www.telerik.com/download.aspx trial] version of Telerik RadControls for Windows Phone 8, for production purpose please download the [http://www.telerik.com/purchase.aspx 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==
 
==Source Code==
 
* The full source code of the example is available here: [[File: BirthdayCalendar.zip]]
 
* The full source code of the example is available here: [[File: BirthdayCalendar.zip]]
 +
 +
[[ar:Birthday Calendar for Windows Phone (Arabic)]]
 +
 +
[[Category:PIM on Windows Phone]]

Latest revision as of 13:48, 27 June 2013

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
Compatibility
Platform(s): Windows Phone 7.5 and later
Windows Phone 8
Windows Phone 7.5
Platform Security
Signing Required: Self-Signed
Capabilities: ID_CAP_APPOINTMENTS, ID_CAP_CONTACTS
Article
Keywords: Facebook events
Created: somnathbanik (25 Apr 2014)
Last edited: hamishwillee (27 Jun 2013)

Contents

[edit] Introduction

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 account.

[edit] Implementation

[edit] 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.

[edit] 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" />
</StackPanel>
<!--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>
</StackPanel>
<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}">
</telerikInput:RadCalendar>
<telerikPrimitives:RadDataBoundListBox x:Name="AppointmentsList" Height="129" Margin="-12,8,0,0" EmptyContent="There are no birthday for the selected day.">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<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"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>
</StackPanel>
</StackPanel>
</Grid>

[edit] 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;
try
{
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));
}
else
{
userGreetings.Text = "Hello, sign in successful!";
}
}
catch (LiveConnectException exception)
{
userGreetings.Text = "API Error : " +
exception.Message;
}
  • 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"];
BirthdayData.ListBirthdayData.Clear();
foreach (IDictionary<string, object> bdayInfo in data)
{
string tempTime = "00:00:00";
BirthdayStructure bdayData = new BirthdayStructure();
bdayData.id = (string)bdayInfo["id"];
bdayData.name = (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;
BirthdayData.ListBirthdayData.Add(bdayData);
}
}
  • 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;
return;
}
DisplayAppointmentsForDate((e.NewValue as DateTime?).Value);
}

[edit] Summary

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.

[edit] Source Code

This page was last modified on 27 June 2013, at 13:48.
400 page views in the last 30 days.
×