#!perl
use strict;
use warnings;
use WWW::Facebook::API::Simple;

my $client = WWW::Facebook::API::Simple->new(
    desktop        => 1,
    throw_errors   => 1,
    parse_response => 1,    # uses XML::Simple if set to 1
);

# Session initialization
my $token = $client->auth->create_token;

# prompts for login credentials from STDIN
$client->login->login($token);
$client->auth->get_session( auth_token => $token );

# Dump XML data returned
use Data::Dumper;
my @friends = @{ $client->friends->get };
print Dumper $client->friends->are_friends(
    uids1 => [ @friends[ 0, 1, 2, 3 ] ],
    uids2 => [ @friends[ 4, 5, 6, 7 ] ],
);

my $unread_pokes = $client->notifications->get->{pokes}->[0]->{unread}->[0];
print "You have $unread_pokes unread poke(s).";

my @users =
    @{ $client->users->get_info( uids => \@friends, fields => ['quotes'] ) };
print "Number of friends:" . @users . "\n";

# Get number of quotes by derefrencing, and then removing the null items (hash
# refs)
my @quotes = grep !ref, map { @{ $_->{'quotes'} } } @users;
print "Number of quotes: " . @quotes . "\n";
print "Random quote: " . $quotes[ int rand @quotes ] . "\n";

$client->auth->logout;
