Ejemplo n.º 1
0
        private void wc_openHandler3(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string jsonstr = e.Result.ToString();
                JObject obj = JObject.Parse(jsonstr);
                JArray items = (JArray)obj["data"];

                List<FBView> lists = new List<FBView>();
                DateTime now = DateTime.Now;
                for (int i = 0; i < items.Count; i++)
                {

                    JObject item = (JObject)items[i];

                    FBView list = new FBView();
                    list.id = (string)item["id"];
                    list.name = (string)item["from"]["name"];
                    if ((string)item["type"] == "status")
                    {
                        list.text = (string)item["message"];
                        list.cap_vis = Visibility.Collapsed;
                    }
                    else
                    {
                        if (item["message"] != null)
                            list.text = (string)item["message"];
                        else
                            list.text = (string)item["name"];
                        list.cap_vis = Visibility.Collapsed;
                        if (item["caption"] != null)
                        {
                            list.caption = (string)item["caption"];
                            list.cap_vis = Visibility.Visible;
                        }
                    }

                    list.img_vis = Visibility.Collapsed;
                    if (item["picture"] != null)
                    {
                        list.img1 = (string)item["picture"];
                        list.img_vis = Visibility.Visible;
                    }
                    DateTime pt = DateTime.Parse((string)item["created_time"]);
                    TimeSpan tsp = now - pt;
                    list.thumb_img = string.Format("http://graph.facebook.com/{0}/picture", (string)item["from"]["id"]);
                    if (tsp.Days > 0)
                        list.time = tsp.Days + "일 전";
                    else if (tsp.Hours > 0)
                        list.time = tsp.Hours + "시간 전";
                    else
                        list.time = tsp.Minutes + "분 전";

                    if (item["comments"] != null)
                    {
                        list.comment = string.Format("댓글 {0}개", item["comments"]["count"]);
                    }
                    else
                    {
                        list.comment = "댓글 0개";
                    }
                    list.like = "0";
                    if (item["likes"] != null)
                    {
                        if (item["likes"]["count"] != null)
                        {
                            list.like = item["likes"]["count"].ToString();
                            list.comment += string.Format("  좋아요 {0}명", item["likes"]["count"]);
                        }
                    }

                    lists.Add(list);
                }
                if (lists.Count > 0)
                {
                    loadtext.Visibility = Visibility.Collapsed;
                    pgbar.Visibility = Visibility.Collapsed;
                    listdata3.ItemsSource = lists;
                    listdata3.Visibility = Visibility.Visible;
                }
                else
                {
                    pgbar.Visibility = Visibility.Collapsed;
                    loadtext.Text = "No items";
                }

            }
            else
            {
                pgbar.Visibility = Visibility.Collapsed;
                loadtext.Text = "No items";
                MessageBox.Show("Your facebook open api is expired. Please re-login facebook account", "Sorry", MessageBoxButton.OK);
            }
        }
Ejemplo n.º 2
0
        private void wc_openHandler2(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                String jsonstr = e.Result.ToString();
                jsonstr = "{\"data\": " + jsonstr + "}";
                JObject obj = JObject.Parse(jsonstr);
                JArray items = (JArray)obj["data"];

                List<FBView> lists = new List<FBView>();
                DateTime now = DateTime.Now;
                for (int i = 0; i < items.Count; i++)
                {

                    JObject item = (JObject)items[i];

                    FBView list = new FBView();
                    list.id = (string)item["thread_id"];
                    list.name = (string)item["subject"];
                    list.text = (string)item["snippet"];
                    if (item["recipients"].Count() == 1)
                        list.thumb_img = string.Format("http://graph.facebook.com/{0}/picture",item["recipients"][0].ToString());
                    else
                    {
                        if((string)settings["facebook_id"] == item["recipients"][0].ToString())
                            list.thumb_img = string.Format("http://graph.facebook.com/{0}/picture",item["recipients"][1].ToString());
                        else
                            list.thumb_img = string.Format("http://graph.facebook.com/{0}/picture",item["recipients"][0].ToString());
                    }

                    DateTime pt = ConvertTimestamp((long)item["updated_time"]);
                    TimeSpan tsp = now - pt;

                    if (tsp.Days > 0)
                        list.time = tsp.Days + "일 전";
                    else if (tsp.Hours > 0)
                        list.time = tsp.Hours + "시간 전";
                    else
                        list.time = tsp.Minutes + "분 전";

                    lists.Add(list);
                }
                if (lists.Count > 0)
                {
                    loadtext.Visibility = Visibility.Collapsed;
                    pgbar.Visibility = Visibility.Collapsed;
                    listdata2.ItemsSource = lists;
                    listdata2.Visibility = Visibility.Visible;
                }
                else
                {
                    pgbar.Visibility = Visibility.Collapsed;
                    loadtext.Text = "No items";
                }
            }
            else
            {
                pgbar.Visibility = Visibility.Collapsed;
                loadtext.Text = "No items";
                MessageBox.Show("Your facebook open api is expired. Please re-login facebook account", "Sorry", MessageBoxButton.OK);
            }
        }