Advertisement
Guest User

Untitled

a guest
Oct 27th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. private void GetFriends()
  2.         {
  3.             var fb = new FacebookClient(_accessToken);
  4.  
  5.             fb.GetCompleted += (o, e) =>
  6.             {
  7.                 if (e.Error != null)
  8.                 {
  9.  
  10.                     Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
  11.                     return;
  12.                 }
  13.  
  14.                 var result = (IDictionary<string, object>)e.GetResultData();
  15.                 var data = (IList<object>)result["data"];
  16.  
  17.                 var result0 = ((IList<object>)((IDictionary<string, object>)data[0])["fql_result_set"]);
  18.                 var result1 = ((IList<object>)((IDictionary<string, object>)data[1])["fql_result_set"]);
  19.  
  20.                 var friends = (from IDictionary<string, object> info in result0
  21.                                select new Friend()
  22.                                {
  23.                                    Id = double.Parse(info["uid"].ToString()),
  24.                                    Name = info["name"].ToString(),
  25.                                    ImageLink = info["pic_square"].ToString(),
  26.                                    Status = info["online_presence"] != null ? info["online_presence"].ToString() : string.Empty
  27.                                }).ToList();
  28.  
  29.  
  30.                 var totalFriendCount = (from IDictionary<string, object> info in result1 select double.Parse(info["friend_count"].ToString())).SingleOrDefault();
  31.  
  32.  
  33.  
  34.  
  35.                 Dispatcher.BeginInvoke(() =>
  36.                 {
  37.  
  38.                              listBox1.ItemsSource = friends;
  39.                 });
  40.             };
  41.  
  42.  
  43.  
  44.             var query = string.Format("SELECT uid,name,pic_square,online_presence FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) order by name", "me()");
  45.             var query2 = string.Format("SELECT friend_count FROM user WHERE uid={0}", "me()");
  46.             fb.GetAsync("fql", new
  47.             {
  48.                 q = new
  49.                     {
  50.                         query,
  51.                         query2
  52.                     }
  53.             });
  54.  
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement