Skip to content

Instantly share code, notes, and snippets.

@koush
Created August 14, 2010 04:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koush/523957 to your computer and use it in GitHub Desktop.
Save koush/523957 to your computer and use it in GitHub Desktop.
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