DESCRIPTION

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:

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:

The callback URL for your application. See the Facebook API documentation.
Just a convenient place holder for the value.

call_success( $is_success, $error_message )

Takes in two values, the first setting the object's last_call_success
attribute, and the second setting the object's last_error attribute. Returns
an array reference containing the last_call_success and last_error values, in
that order:

If the file is found, and the environment variables are already set, then the
variables will not be changed.

debug(0|1)

A boolean set to either true or false, determining if debugging messages
should be carped for REST calls. Defaults to 0.

desktop(0|1)

A boolean signifying if the client is being used for a desktop application.
If $ENV{'WFA_DESKTOP'} is set, all instances will be initialized with its
value. Defaults to 0 otherwise. See the Facebook API documentation for more
information.

format('JSON'|'XML')

The default format to use if none is supplied with an API method call.
Currently available options are XML and JSON. Defaults to JSON.

last_call_success(1|0)

A boolean set to true or false, to show whether the last call was successful
or not. Called by "call_success". Defaults to 1.

last_error( $error_message )

A string holding the error message of the last failed call to the REST server.
Called by "call_success". Defaults to undef.

next( $new_default_next_url )

See the Facebook API documentation's Authentication Guide. Just a convenient
place holder for the value.

parse(1|0)

Defaults to 1. If set to true, the response returned by each method call will
be a Perl structure (see each method for the structure it will return). If it
is set to 0, the response string from the server will be returned. (The
response string is unescaped if the 'desktop' attribute is false).

popup( $popup )

See the Facebook API documentation's Authentication Guide. Just a convenient
place holder for the value.

query( $query )

Stores the current query object to use (either CGI or Apache::Request)
but really anything that implements the "param()" method can be used. N.B.
When using "require_*" methods below, Apache::Request will croak because it
does not implement a redirect method.

secret( $new_secret_key )

For a desktop application, this is the secret that is used for calling
"auth->create_token" and "auth->get_session". For a web application,
secret is used for all calls to the API. If $ENV{'WFA_SECRET'} is set,
all instances will be initialized with its value. See the Facebook API
documentation under Authentication for more information.

server_uri( $new_server_uri )

The server uri to access the Facebook REST server. Default is
'http://api.facebook.com/restserver.php'. Used to make calls to the
Facebook server, and useful for testing. See the Facebook API documentation.

session_expires( $new_expires )

The session expire timestamp for the client's user. Automatically set when
"$client->auth->get_session" is called. See the Facebook API
documentation.

session_key( $new_key )

The session key for the client's user. Automatically set when
"$client->auth->get_session" is called. See the Facebook API documentation.

session_uid( $new_uid )

The session's uid for the client's user. Automatically set when
"$client->auth->get_session" is called. See the Facebook API documentation.

skipcookie(0|1)

See the Facebook API documentation's Authentication Guide. Just a convenient
place holder for the value.

throw_errors(0|1)

A boolean set to either true of false, signifying whether or not to "confess"
when an error is returned from the REST server.

ua

The LWP::UserAgent agent used to communicate with the REST server.
The agent_alias is initially set to ``Perl-WWW-Facebook-API/0.4.18''.

PUBLIC METHODS

call( $method, %args )

The method which other submodules within WWW::Facebook::API use
to call the Facebook REST interface. It takes in a string signifying the method
to be called (e.g., 'auth.getSession'), and key/value pairs for the parameters
to use:
$client->call( 'auth.getSession', auth_token => 'b3324235e' );

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.

generate_sig( params => $params_hashref, secret => $secret )

Generates a sig when given a parameters hash reference and a secret key.

get_add_url( %params )

Returns the URL to add your application with the parameters (that are given)
included. Note that the API key and the API version parameters are also
included automatically. If the "next" parameter is passed in, it's
string-escaped. Used for platform applications:

Called by all the above "get_*_url" methods above. $type can be 'login',
'app', 'add', 'facebook', 'infinite_session', or 'custom'.
@args contains the query parameters for the the cases when $type is not
'app' or 'facebook'. In the case of 'custom', the first item in
@args is the url path relative to the facebook website. All of the
"get_*_url" methods correspond to the ones in the official PHP client.

log_string($params_hashref, $response)

Pass in the params and the response from a call, and it will make a formatted
string out of it showing the parameters used, and the response received.

redirect( $url, $query_object )

Called by "require()" to redirect the user either within the canvas or
without. If no <$query_object> is defined, then whatever is in "$client->query" will be used. (See WWW::Facebook::API::Canvas) If no
redirect is required, nothing is returned. That is the only case when there is
no return value. If a redirect is required, there are two cases that are
covered:

user not logged in

If there isn't a user logged in to Facebook's system, then a redirect to the Facebook
login page is printed to STDOUT with a next parameter to the appropriate page.
The redirect is called with the the CGI module that comes standard with perl.
The return value in this case is 1.

user logged in

If the user is logged in to Facebook, and a redirect is required, the
necessary FBML is returned: "<fb:redirect url="WHATEVER">".
So the return value is the FBML, which you can then print to STDOUT.

require_add( $query )

Redirects the user to what "get_add_url()" returns. See "require()" below
for the $query parameter.

require_frame( $query )

Redirects the user to what "get_login_url( canvas =" '1' )> returns. See
"require()" below for the $query parameter.

require_login( $query )

Redirects the user to what "get_login_url()" returns. See "require()" below
for the $query parameter.

require( $what, $query )

The official PHP client has "require_*" methods that take no arguments.
Logically, you better know what you want to require when you call each of
them, so this API consolidates them into one method. The valid values for
$what are 'add', 'frame', and 'login'. $query is the query
object to use (most likely CGI). If $query is undefined, the value of
" $client-"query >> is used.

Returns its parameter with all the escape sequences unescaped. If you're using
a web app, this is done automatically to the response.

verify_sig( sig => $expected_sig, params => $params_hashref )

Checks the signature for a given set of parameters against an expected value.

PRIVATE METHODS

_add_url_params( %params )

Called by both "get_login_url" and "get_add_url" to process any of their
parameters. Prepends the api_key and the version number as parameters and
returns the parameter string.

_check_values_of($params_hashref)

Makes sure all the values of the $params_hashref that need to be set are
set. Uses the defaults for those values that are needed and not supplied.

_format_and_check_params( $method, %args )

Format method parameters (given in %args) according to Facebook API
specification. Returns a list of items: A hash reference of the newly
formatted params (based on %params) and the raw data (and filename, if
passed in) if the call is a photo or video upload:

Determines if the response is an error, and logs it appropriately. Returns
true if response is an error, false otherwise.

is_empty_response( $response )

Determines if the response is an empty hash or array reference. Returns true
if the response is empty, false otherwise.

_post_request( $params_hashref, $sig, $raw_data, $filename )

Used by "call" to post the request to the REST server and return the
response. $raw_data and $filename are used when uploading a photo or
video to Facebook.

_parse($string)

Parses the response from a call to the Facebook server to make it a Perl data
structure, and returns the result.

_parser()

Returns a new instance of JSON::Any.

_reformat_response( $params, $response )

Reformats the response according to whether the app is a desktop app, if the
response should be parsed (i.e., changed to a Perlish structure), if the
response is empty, etc. Returns the reformatted response.

DIAGNOSTICS

Unable to load JSON module for parsing: %s

JSON::Any was not able to load one of the JSON modules it uses to parse
JSON. Please make sure you have one (of the several) JSON modules it can use
installed.

Error during REST call: %s

This means that there's most likely an error in the server you are using to
communicate to the Facebook REST server. Look at the traceback to determine
why an error was thrown. Double-check that "server_uri" is set to the right
location.

You're using a private method call and you're not calling it in list context.
It returns a list of items, all of which should be interesting to you.

Cannot open %s

Cannot open the configuration file. Make sure the filename is correct and that
the program has the appropriate permissions.

Cannot close %s

Cannot close the configuration file. Make sure the filename is correct and
that the program has the appropriate permissions.

FAQ

Id numbers returned by Facebook are being rounded. What is the problem?

The JSON module that is installed on your system is converting the numbers to
Perl and is losing precision in the process. Make sure you have the latest
JSON::XS module installed or JSON::DWIW (any recent version of either
should work).

How do I run the examples in the examples directory?

There are two types of examples in the examples directory, desktop-based and
web-based. With desktop-based, the api key and secret key are prompted for on
STDIN, and then the user's browser is opened and directed to the Facebook
log in page. Currently, the desktop-based examples pause for 20 seconds to
allow for the user to enter in their credentials.

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):

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):

LICENSE AND COPYRIGHT

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.