public List<Friend> Get() { WebClient webClient = new WebClient(); string rawResult = webClient.DownloadString(String.Format(FACEBOOK_FRIENDS, "me", "5000", "0", "id,name,location,picture,birthday", _accessToken)); // string result = "{\"data\": [{\"id\": \"510453820\",\"name\": \"Hakan Vurel\",\"installed\": true},{\"id\": \"100003817945807\",\"name\": \"Michel van Lieshout\"}], \"paging\": {\"next\": \"https://graph.facebook.com/100001465318209/friends?fields=id\u00252Cname\u00252Cinstalled&limit=5000&offset=5000\"}}"; JObject result = JObject.Parse(rawResult); List<Friend> friends = new List<Friend>(); Friend friend; foreach (JToken jFriend in result["data"]) { friend = new Friend(); friend.FacebookId = jFriend["id"].Value<string>(); friend.Name = jFriend["name"].Value<string>(); friends.Add(friend); } return friends; }
private IList<Friend> GetOwnFacebookFriendList(string accessToken) { try { IList<Friend> faceBookUserList = new List<Friend>(); FacebookClient client = new FacebookClient(accessToken); var friendListDataString = client.Get("/me/friends"); MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(Convert.ToString(friendListDataString).ToCharArray())); StreamReader sr = new StreamReader(ms); Dictionary<string, object> facebookJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(sr.ReadToEnd()); foreach (KeyValuePair<string, object> json in facebookJson) { switch (json.Key.ToLower()) { case "data": List<object> dataList = JsonConvert.DeserializeObject<List<object>>(json.Value.ToString()); int index = 0; while (index != dataList.Count()) { Dictionary<string, string> friendDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(Convert.ToString(dataList[index])); Friend fbUserObj = new Friend(); foreach (KeyValuePair<string, string> friend in friendDictionary) { if (friend.Key == "name") fbUserObj.Name = friend.Value; else { fbUserObj.FacebookId = friend.Value; fbUserObj.ProfileImg = string.Format("https://graph.facebook.com/{0}/picture", friend.Value); } } try { faceBookUserList.Add(fbUserObj); } catch (Exception ex) { //Utilities.ErrorLogger.LogException(ex, ex.Message); } index++; } break; } } return faceBookUserList; } catch { return null; } }