Skip to content

Instantly share code, notes, and snippets.

@jwalsh
Created August 17, 2010 20:15
Show Gist options
  • Save jwalsh/531809 to your computer and use it in GitHub Desktop.
Save jwalsh/531809 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use JSON;
my $ua = new LWP::UserAgent;
$ua->agent("wal.sh/0.0");
my $graph_base = "https://graph.facebook.com/";
# Acquire the OAuth token before moving forward
my $access_token = "?access_token=";
my $max_shared = 0;
### Obtain own likes for processing against friend likes
my $req = new HTTP::Request GET => my $friends_url = $graph_base . "me" . "/likes" . $access_token;
my $res = $ua->request($req);
if ($res->is_success) {
my $my_likes = from_json($res->decoded_content);
my $i = 0;
### Obtain a list of friends for the matrix
my $req = new HTTP::Request GET => $graph_base . "me" . "/friends" . $access_token;
my $res = $ua->request($req);
if ($res->is_success) {
my $friends = from_json($res->decoded_content);
foreach my $friend (@{$friends->{data}}){
my $shared_likes = 0;
my $shared_copy;
my $likes_copy;
my $req = new HTTP::Request GET => $graph_base . $friend->{id} . "/likes" . $access_token;
my $res = $ua->request($req);
my $their_likes = from_json($res->decoded_content);
my $i = 0;
foreach my $like (@{$their_likes->{data}}){
$i++;
# print $i.". " . $like->{name} . " (" . $like->{id} . ")\n";
$likes_copy = $likes_copy . $like->{name} . "; ";
# Complete the rough test
foreach my $my_like (@{$my_likes->{data}}) {
# print $like->{id} . " = " . $my_like->{id} . " \n";
if ( $like->{id} == $my_like->{id} ) {
$shared_likes++;
# $shared_copy = $shared_copy . $like->{name} . " (" . $like->{id} . "); ";
$shared_copy = $shared_copy . $like->{name} . "; ";
}
}
}
if ( $shared_likes > 0 ) {
print $friend->{name} . " shares " . $shared_likes . " likes: ";
# print $friend->{name} . " (" . $friend->{id} . ") shares " . $shared_likes . " likes: ";
print $shared_copy . "\n\n";
}
# print "\n=======================\n" . $friend->{name} . ": " . $likes_copy . "\n=======================\n";
if ( $shared_likes > $max_shared ) {
$max_shared = $shared_likes;
}
}
} else {
die "Could not get content";
}
} else {
die "Could not get a list of your likes.";
}
print "Max shared: " . $max_shared;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment