| WWW::Facebook::API(3pm) | User Contributed Perl Documentation | WWW::Facebook::API(3pm) |
WWW::Facebook::API - Facebook API implementation
This document and others distributed with this module describe WWW::Facebook::API version 0.4.18
use WWW::Facebook::API;
# @ENV{qw/WFA_API_KEY WFA_SECRET WFA_DESKTOP/} are the initial values,
# so use those if you only have one app and don't want to pass in values
# to constructor
my $client = WWW::Facebook::API->new(
desktop => 0,
api_key => 'your api key',
secret => 'your secret key',
);
# Change API key and secret
print "Enter your public API key: ";
chomp( my $val = <STDIN> );
$client->api_key($val);
print "Enter your API secret: ";
chomp($val = <STDIN> );
$client->secret($val);
# not needed if web app (see $client->canvas->get_fb_params)
$client->auth->get_session( $token );
use Data::Dumper;
my $friends_perl = $client->friends->get;
print Dumper $friends_perl;
my $notifications_perl = $client->notifications->get;
print Dumper $notifications_perl;
# Current user's quotes
my $quotes_perl = $client->users->get_info(
uids => $friends_perl,
fields => ['quotes']
);
print Dumper $quotes_perl;
$client->auth->logout;
A Perl implementation of the Facebook API, working off of the canonical Java and PHP implementations. By default it uses JSON::Any to parse the response returned by Facebook's server. There is an option to return the raw response in either XML or JSON (See the "parse" method below). As the synopsis states, the following environment variables are used to set the defaults for new instances:
WFA_API_KEY
WFA_SECRET
WFA_SESSION_KEY
WFA_DESKTOP
Additionally, for each instance that is created, the following environment variables are used if no values are set:
WFA_API_KEY_APP_PATH
WFA_SECRET_APP_PATH
WFA_SESSION_KEY_APP_PATH
WFA_DESKTOP_APP_PATH
Where "APP_PATH" is replaced by whatever $client->app_path returns, with all non-alphanumeric characters replaced with an underscore and all characters upcased (e.g., foo-bar-baz becomes FOO_BAR_BAZ).
my $client = WWW::Facebook::API->new(
parse => 1,
format => 'JSON',
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',
throw_errors => 1,
);
$copy = $client->new;
All method names from the Facebook API are lower_cased instead of CamelCase.
$client->auth->get_session( $client->auth->create_token );
$client->auth->get_session;
And that's all you really have to do (but see WWW::Facebook::API::Auth for details about opening a browser on *nix for Desktop apps). "get_session" automatically sets "session_uid", "session_key", and "session_expires" for $client. It returns nothing.
If the desktop attribute is set to false the $token must be the auth_token returned from Facebook to your web app for that user:
if ( $q->param('auth_token') ) {
$client->auth->get_session( $q->param('auth_token') );
}
"get_session" automatically sets "session_uid", "session_key", and "session_expires" for $client. It returns nothing.
See WWW::Facebook::API::Auth for details.
$response = $client->canvas->get_user( $q )
$response = $client->canvas->get_fb_params( $q )
$response = $client->canvas->get_non_fb_params( $q )
$response = $client->canvas->validate_sig( $q )
$response = $client->canvas->in_fb_canvas( $q )
$response = $client->canvas->in_frame( $q )
$response = $client->data->set_cookie( uid => 23, qw/name foo value bar/);
$cookies = $client->data->get_cookies(
uid => 4534,
name => 'foo',
);
$response = $client->events->get(
uid => 'uid',
eids => [@eids],
start_time => 'utc',
end_time => 'utc',
rsvp_status => 'attending|unsure|declined|not_replied',
);
$response = $client->events->get_members( eid => 233 );
$response = $client->fbml->set_ref_handle( handle => '', fbml => '');
$response = $client->fbml->refresh_img_src( url => '');
$response = $client->fbml->refresh_ref_url( url => '');
$response
= $client->feed->publish_story_to_user(
title => 'title',
body => 'markup',
...
);
$response
= $client->feed->publish_action_of_user(
title => 'title',
body => 'markup',
...
);
$response
= $client->feed->publish_templatized_action(
actor_id => 'title',
title_template => 'markup',
...
);
$response = $client->fql->query( query => 'FQL query' );
$response = $client->friends->get;
$response = $client->friends->get_app_users;
$response
= $client->friends->are_friends( uids1 => [1,5,8], uids2 => [2,3,4] );
$response = $client->friends->get_lists;
$response = $client->groups->get( uid => 234324, gids => [2423,334] );
$response = $client->groups->get_members( gid => 32 );
$response = $client->notifications->get;
$response = $client->notifications->send(
to_ids => [ 1, 3 ],
notification => 'FBML notification markup',
);
$response = $client->notifications->send_email(
recipients => [1, 2343, 445],
subject => 'subject',
text => 'text version of email body',
fbml => 'fbml version of email body',
);
$response = $client->pages->get_info(
page_ids => [@pages],
fields => [@fields],
uid => 'user',
type => 'page type',
);
$page_added_app = $client->pages->is_app_added( page_id => 'page' );
$is_admin = $client->pages->is_admin( page_id => 'page' );
$is_fan = $client->pages->is_fan( page_id => 'page', uid => 'uid' )
$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',
);
$response = $client->profile->get_fbml( uid => 3 );
$response = $client->profile->set_fbml( uid => 5,
profile => 'markup',
profile_action => 'markup',
mobile_profile => 'markup',
);
$response = $client->users->get_info(
uids => 2343,
fields => [ qw/about_me quotes/ ]
);
$uid = $client->users->get_logged_in_user;
$response = $client->users->has_app_permission(
ext_perm => 'status_update|photo_upload'
);
$app_added = $client->users->is_app_user;
$response = $client->users->set_status(
status => 'status message',
clear => 1|0,
);
These are methods to get/set the object's attributes.
http://www.facebook.com/apps/application.php?id=THIS_NUMBER
Remember, "WWW::Facebook::API" is not that clairvoyant: You must first set this number (when calling "new()") in order to use it.
my $response = $client->call_success( 1, undef );
if ( $response->[0] == 1 ) {
print 'Last call successful';
}
if ( not defined $response->[1] ) {
print 'Error message is undefined';
}
$client->call_success( 0,'2: The service is not available at this time.');
$response = $client->call_success;
if ( not $response->[0] ) {
print 'Last call unsuccessful';
}
if ( not defined $response->[1] ) {
print "Error $response->[1]";
}
The "call" method calls this method, and shouldn't need to be called to set anything, just to get the value later if "throw_errors" is false.
WFA_API_KEY_MYAPP=383378efa485934bc
WFA_SECRET_MYAPP=234234ac902f340923
WFA_SESSION_KEY_MYAPP=34589349abce989d
WFA_DESKTOP_MYAPP=1
If the file is found, and the environment variables are already set, then the variables will not be changed.
For all calls, if " parse " is set to true and an empty hash/array reference is returned from facebook, nothing will be returned instead of the empty hash/array reference.
$response = $client->get_add_url( next => 'http://my.website.com' );
# prints http://www.facebook.com/app.php?api_key=key&v=1.0
# &next=http%3A%2F%2Fmy.website.com
print $response;
$response = $client->get_facebook_url( 'apps' );
print $response; # prints http://apps.facebook.com
$response = $client->get_infinite_session_url;
# prints http://www.facebook.com/codegen.php?api_key=key&v=1.0
print $response;
From what I've seen, the session keys that Facebook returns don't expire automatically, so as long as you don't call $client->auth->logout, you shouldn't even need to worry about this.
$response = $client->get_login_url( next => 'http://my.website.com' );
# prints http://www.facebook.com/login.php?api_key=key&v=1.0
# &next=http%3A%2F%2Fmy.website.com
print $response;
($params, $raw_data, $filename) = $self->_format_and_check_params( $method, %args );
With web-based, you have to pass in the api key, secret key, and app path to the constructor, and then place the script at the callback url you specified in the Facebook setup for your application. For instance, when using the web-based example, you might have the following callback url (note the trailing slash):
http://www.example.com/facebook-canvas-json/
You have to make sure the required Perl modules are in the @INC path for the web server process, otherwise there will be a 500 Internal Server error. The easiest way to do that is to put the following at the top of the example script (as long as "path-to-perl5-libs" is readable by the web server process):
use lib "path-to-perl5-libs";
WWW::Facebook::API requires no configuration files or environment variables.
version Crypt::SSLeay Digest::MD5 JSON::Any Time::HiRes LWP::UserAgent
None.
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>.
http://github.com/unobe/perl-wfa/tree/master
There are some live tests included, but they are only run if the
following environment variables are set:
WFA_API_KEY_TEST
WFA_SECRET_TEST
WFA_SESSION_KEY_TEST
Additionally, if your app is a desktop one, you must set "WFA_DESKTOP_TEST". Also, the session key must be valid for the API key being used.
To enable POD coverage and POD formattings tests, set "PERL_TEST_POD" to true. To enable Perl::Critic tests, set "_PERL_TEST_CRITIC" to true.
David Romano "<unobe@cpan.org>"
Anthony Bouvier "none"
Clayton Scott "http://www.matrix.ca"
David Leadbeater "http://dgl.cx"
Derek Del Conte "derek@delconte.org"
Gisle Aas "none"
J. Shirley "<jshirley@gmail.com>"
Jim Spath "<jspath@gmail.com>"
Kevin Riggle "none"
Larry Mak "none"
Louis-Philippe "none"
Matt Sickler "<imMute@mail.msk3.ath.cx>"
Nick Gerakines "<nick@socklabs.com>"
Olaf Alders "<olaf@wundersolutions.com>"
Patrick Michael Kane "<pmk@wawd.com>"
Ryan D Johnson "ryan@innerfence.com"
Sean O'Rourke "<seano@cpan.org>"
Shawn Van Ittersum "none"
Simon Cavalletto "<simonm@cavalletto.org>"
Skyler Clark "none"
Thomas Sibley "<tsibley@cpan.org>"
Copyright (c) 2007-2010, 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.
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.
| 2022-06-28 | perl v5.34.0 |