Net-Social-Service-Facebook

 view release on metacpan or  search on metacpan

lib/Net/Social/Service/Facebook.pm  view on Meta::CPAN


    sub make_client {
        my ($api_key, $secret) = @_;

        my $client = WWW::Facebook::API->new(
                parse        => 1,
                throw_errors => 1,
        );
        $client->api_key($api_key);
        $client->secret($secret);
        $client->desktop(1);
        return $client;
    }

=head1 METHODS

=head2 friends

Returns your friends. It defines the keys C<uid>, C<name> and C<type>.

=cut

sub friends {
    my $self = shift;
    return () unless $self->{_logged_in};
    my $user        = $self->{_details}->{username};
    my $key         = $self->{_details}->{api_key};
    my $sess_key    = $self->{_details}->{session_key}; 
    my $sess_secret = $self->{_details}->{session_secret};
    my $client = WWW::Facebook::API->new(
        desktop      => 1,
        parse        => 1,
        throw_errors => 1,        
#        debug => 1,
    );
    #$secret = $sess_secret if defined $sess_secret.
    $client->api_key($key);
    $client->session_key($sess_key);
    $client->secret($sess_secret);
    $client->desktop(1);

    my %friends;
    my $uids = $client->friends->get;
    # First get their details
    foreach my $friend (@{$client->users->get_info(uids=>$uids, 
                                                   fields=>[qw(name uid )])
                        })
    {
        $friends{$friend->{uid}} = { id => $friend->{uid}, name => $friend->{name}, type => MUTUAL };



( run in 0.557 second using v1.01-cache-2.11-cpan-299005ec8e3 )