The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::Facebook::API - Facebook API implementation

VERSION

This document describes WWW::Facebook::API version 0.2.1

SYNOPSIS

    use WWW::Facebook::API;
    
    my $client = WWW::Facebook::API->new(
        desktop => 1,
        throw_errors => 1,
        parse_response => 1, # uses XML::Simple if set to 1
    );
    
    # Session initialization
    my $token
        = $client->auth->create_token->{auth_createToken_response}->[0]->{content};
    
    # 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->{friends_get_response}->[0]->{uid} };
    print Dumper $client->friends->are_friends(
        uids1 => [@friends[0,1,2,3]],
        uids2 => [@friends[4,5,6,7]],
    );
    
    my $unread_pokes
        = $client->notifications->get
            ->{notifications_get_response}->[0]->{pokes}->[0]->{unread}->[0];
    print "You have $unread_pokes unread poke(s).\n";
    
    my @users
        = @{ $client->users->get_info( uids => \@friends, fields => ['quotes'])
                ->{users_getInfo_response}->[0]->{user}
    };
    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;

DESCRIPTION

A Perl implementation of the Facebook API, working off of the canonical Java and PHP implementations. If you have XML::Simple or JSON::XS installed, then you can have them parse the response returned by Facebook's server, instead of parsing them by hand. In the case that you want the format to be XML, XML::Simple is used with ForceArray = 1> and KeepRoot = 1> values. Also see WWW::Facebook::API::Simple for a bit easier response values when working with XML::Simple.

SUBROUTINES/METHODS

new

Returns a new instance of this class. You are able to pass in any of the method names in WWW::Facebook::API::Base to set the value (except the methods call, new, and its internal methods ): my $client = WWW::Facebook::API->new( format => 'JSON', parse_response => 1, server_uri => 'http://www.facebook.com/restserver.php', secret => 'application_secret_key', api_key => 'application_key', session_key => 'session_key', session_expires => 'session_expires', session_uid => 'session_uid', desktop => 1, api_version => '1.0', callback => 'callback_url', next => 'next', popup => 'popup', skipcookie => 'skip_cookie', mech => WWW::Mechanize->new, errors => WWW::Facebook::API::Errors->new( base => $base ), );

See WWW::Facebook::API::Base for the default values.

auth

auth namespace of the API (See WWW::Facebook::API::Auth). All method names from the Facebook API are lower_cased instead of CamelCase: my $token = $client->auth->create_token; $client->auth->get_session( auth_token => $token );

You only need ot call $client->auth->create_token if you're running a Desktop application. Otherwise, the token is created during the user's login, which is sent to your callback URL as a single parameter (auth_token).

login

Not defined in the API, but useful for testing with your own account. Asks for username and password (not stored outside of run) to authenticate token. $new_token = $client->login->login( $token );

$new_token is the token that will be used for the rest of the session.

events

events namespace of the API (See WWW::Facebook::API::Events). All method names from the Facebook API are lower_cased instead of CamelCase: my $events = $client->events->get( uid => 234233, eids => [23,2343,54545] ); my $members = $client->events->getMembers( eid => 233 );

fbml

fbml namespace of the API (See WWW::Facebook::API::FBML): All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->fbml->set_ref_handle; $response = $client->fbml->refresh_img_src; $response = $client->fbml->refresh_ref_url;

fql

fql namespace of the API (See WWW::Facebook::API::FQL): my $response = $client->fql->query( query => 'FQL query' );

feed

feed namespace of the API (See WWW::Facebook::API::Feed). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->feed->publish_story_to_user( title => 'title', body => 'body', priority => 5, ... ); $response = $client->feed->publish_action_of_user( title => 'title', body => 'body', priority => 7, ... );

friends

friends namespace of the API (See WWW::Facebook::API::Friends). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->friends->get; $response = $client->friends->get_app_users; $response = $client->friends->are_friends( uids => [1,5,7,8], uids2 => [2,3,4]);

groups

groups namespace of the API (See WWW::Facebook::API::Groups). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->groups->get_members( gid => 32 ); $response = $client->groups->get( uid => 234324, gids => [2423,334] );

notifications

notifications namespace of the API (See WWW::Facebook::API::Notifications). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->notifications->get; $response = $client->notifications->send( to_ids => [1], markup => 'markup', no_email => 1, ); $response = $client->notifications->send_request( to_ids => [1], type => 'event', content => 'markup', image => 'string', invite => 0, );

photos

photos namespace of the API (See WWW::Facebook::API::Photos). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->photos->add_tag( pid => 2, tag_uid => 3, tag_text => "me", x => 5, y => 6 ); $response = $client->photos->create_album( name => 'fun in the sun', location => 'California', description => "Summer '07", ); $response = $client->photos->get( aid => 2, pids => [4,7,8] ); $response = $client->photos->get_albums( uid => 1, pids => [3,5] ); $response = $client->photos->get_tags( pids => [4,5] ); $response = $client->photos->upload( aid => 5, caption => 'beach', data => 'raw data', );

profile

profile namespace of the API (See WWW::Facebook::API::Profile). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->profile->get_fbml( uid => 3 ); $response = $client->profile->set_fbml( uid => 5, markup => 'markup' );

update

update namespace of the API (See WWW::Facebook::API::Update). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->update->decode_ids( ids => [5,4,3] );

users

users namespace of the API (See WWW::Facebook::API::Users). All method names from the Facebook API are lower_cased instead of CamelCase: my $response = $client->users->get_info( uids => [12,453,67], fields => ['quotes','activities','books'] );

simple

Defaults to false. WWW::Facebook::API::Simple defaults to true. Compare this module's synopsis with WWW::Facebook::API::Simple to see an example of what difference it makes. If set to true, makes all methods return an easier-to-manage value by dereferencing the top nodes of the XML hierarchy.

DIAGNOSTICS

The errors that are thrown come from WWW::Facebook::API::Base or from others in one of the DEPENDENCIES.

CONFIGURATION AND ENVIRONMENT

WWW::Facebook::API requires no configuration files or environment variables.

DEPENDENCIES

version WWW::Mechanize XML::Simple Digest::MD5 Crypt::SSLeay

INCOMPATIBILITIES

None.

SEE ALSO

WWW::Facebook::FQL for an interface to just work with Facebook's FQL query language.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-www-facebook-api@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

David Romano <unobe@cpan.org>

LICENSE AND COPYRIGHT

Copyright (c) 2007, David Romano <unobe@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.