Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Birthday Calendar for Windows Phone (Arabic)

From Wiki
Jump to: navigation, search

يوضح هذا المقال كيفية دمج أعياد ميلاد أصدقاء الفيسبوك مع تطبيق التقويم باستخدام 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
Windows Phone 8
Windows Phone 7.5
Platform Security
Signing Required: Self-Signed
Capabilities: ID_CAP_APPOINTMENTS, ID_CAP_CONTACTS
Article
Keywords: Facebook events
Translated:
By bintk
Last edited: hamishwillee (18 Jul 2013)

Contents

المقدمة

Windows Phone Calendar APIلا يوفر الفيسبوك أمكانية للوصول إلي اعياد الميلاد و الأحداث / اعياد الميلاد التي نراها في تطبيق التقويم الافتراضي في الجهاز لايمكن تكرارها في اي تطبيقات أخري وسوف نستخدم أحدي الحيل للوصول إلي الأحداث واعياد الميلاد في تقويم الفيس بوك وMicrosoft Live Connect SDK للحصول علي الأحداث واعياد الميلاد من تقويم الفيس بوك .إذا كنت جديداً في الاتصال المباشر مع بيئة التطوير اقترح عليك تصفح هذا المقالGetting user information with the Live Connect API for Windows Phone 7 انه يوفر القدر الكافي من المعلومات لكي تتمكن من فهمها .

Note.pngNote: لجلب الاحداث و اعياد الميلاد من الفيس بوك بأستخدام الاتصال المباشر مع بيئة التطوير , يجب الانتباه ان يكون حسابك في ميكروسوفت مرتبط مع حسابك في الفس بوك .

الخطوات

أنشئ تطبيق ويندوز فون جديد

  • أنشئ تطبيق ويندوز فون باطريقة العادية كما هو معتاد

إضافة عناصر التحكم إلي واجهة المستخدم في التطبيق

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>

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);
}

الملخص

يرجي تحميل الكود المصدري لهذا المثال لمذيد من الفهم حول التعليمات البرمجية المستخدم في صنع هذا المثال .

الكود المصدري

This page was last modified on 18 July 2013, at 06:57.
191 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×