Created
August 14, 2010 04:11
-
-
Save koush/523957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using Newtonsoft.Json.Linq; | |
namespace FacebookChallenge | |
{ | |
class Program | |
{ | |
static readonly string accessToken = "GET YOUR OWN FOO"; | |
static readonly string baseUrl = "https://graph.facebook.com/{0}/{1}?access_token={2}"; | |
static JObject GetJSON(string user, string info) | |
{ | |
return JObject.Parse(new System.IO.StreamReader(System.Net.HttpWebRequest.Create(String.Format(baseUrl, user, info, accessToken)).GetResponse().GetResponseStream()).ReadToEnd()); | |
} | |
static void Main(string[] args) | |
{ | |
var mylikes = from like in GetJSON("me", "likes")["data"].Children() select like["id"].Value<string>(); | |
var friends = from friend in GetJSON("me", "friends")["data"].Children() select new { Id = friend["id"].Value<string>(), Name = friend["name"].Value<string>() }; | |
var shared = from friend in friends select | |
new | |
{ | |
Id = friend.Id, | |
Name = friend.Name, | |
SharedLikes = (from theirLike in GetJSON(friend.Id, "likes")["data"].Children() select theirLike["id"].Value<string>()).Intersect(mylikes).Count() | |
}; | |
var bestfriend = (from friend in shared orderby friend.SharedLikes select friend).Reverse().First(); | |
Console.WriteLine(bestfriend.Name + " " + bestfriend.SharedLikes); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment