GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Facebook::Graph(3) User Contributed Perl Documentation Facebook::Graph(3)

Facebook::Graph - A fast and easy way to integrate your apps with Facebook.

version 1.0801

 my $fb = Facebook::Graph->new;
 my $sarah_bownds = $fb->fetch('sarahbownds');
 my $perl_page = $fb->fetch('16665510298');

Or better yet:

 my $sarah_bownds = $fb->query
    ->find('sarahbownds')
    ->include_metadata
    ->select_fields(qw( id name picture ))
    ->request
    ->as_hashref;

 my $sarahs_picture_uri = $fb->picture('sarahbownds')->get_large->uri_as_string;

You can also do asynchronous calls like this:

 my $sarah = $fb->query->find('sarahbownds');           # making request in background here
 # ... do stuff here ...
 my $hashref = $sarah->as_hashref;                      # handling the response here

Or fetching a response from a URI you already have:

 my $hashref = $fb->request('https://graph.facebook.com/btaylor')->as_hashref;

 my $fb = Facebook::Graph->new(
    app_id          => $facebook_application_id,
    secret          => $facebook_application_secret,
    postback        => 'https://www.yourapplication.com/facebook/oauth/postback',
 );

Get the user to authorize your app (only needed if you want to fetch non-public information or publish stuff):

 my $uri = $fb
    ->authorize
    ->extend_permissions(qw(offline_access publish_stream))
    ->uri_as_string;

 # redirect the user's browser to $uri

Handle the Facebook authorization code postback:

 my $q = Plack::Request->new($env);
 $fb->request_access_token($q->query_param('code'));

 #now retrieve extended access token
 $fb->request_extended_access_token; #extended access token now in $fb->access_token

Or if you already had the access token:

 $fb->access_token($token);
 $fb->request_extended_access_token;

Or simply:

 $fb->request_extended_access_token($token);

Get some info:

 my $user = $fb->fetch('me');
 my $friends = $fb->fetch('me/friends');
 my $sarah_bownds = $fb->fetch('sarahbownds');

This is a Perl interface to the Facebook Graph API <http://developers.facebook.com/docs/api>. With this module you can currently query public Facebook data, query privileged Facebook data, and build a privileged Facebook application. See the TODO for all that this module cannot yet do.

For example code, see Facebook::Graph::Cookbook.

WARNING: The work on this module has only just begun because the Graph API itself isn't very new, and I'm only working on it as I have some tuits. Therefore things are potentially subject to change drastically with each release.

The constructor.

params

A hash of base parameters, just so you don't have to pass them around. If you only want to do public queries then these params are not needed.

access_token
An access token string used to make Facebook requests as a privileged user. Required if you want to make privileged queries or perform privileged actions on Facebook objects.
app_id
The application id that you get from Facebook after registering (<http://developers.facebook.com/setup/>) your application on their site. Required if you'll be calling the "request_access_token", "convert_sessions", or "authorize" methods.
secret
The application secret that you get from Facebook after registering your application. Required if you'll be calling the "request_access_token" or "convert_sessions" methods.
postback
The URI that Facebook should post your authorization code back to. Required if you'll be calling the "request_access_token" or "authorize" methods.

NOTE: It must be a sub URI of the URI that you put in the Application Settings > Connect > Connect URL field of your application's profile on Facebook.

Creates a Facebook::Graph::Authorize object, which can be used to get permissions from a user for your application.

Creates a Facebook::Graph::AccessToken object and fetches an access token from Facebook, which will allow everything you do with Facebook::Graph to work within user privileges rather than through the public interface. Returns a Facebook::Graph::AccessToken::Response object, and also sets the "access_token" property in the Facebook::Graph object.

Note: access_token is optional. Creates a Facebook::Graph::AccessToken object and fetches an (https://developers.facebook.com/docs/facebook-login/access-tokens/#extending) extended access token from Facebook. This method accepts an optional access token. If you have called "request_access_token" already on the Facebook::Graph object and "access_token" is set, then you do not have to pass in an access token. However, if you have an access token stored from a previous object, you will need to pass it in.

code

An authorization code string that you should have gotten by going through the "authorize" process.

Creates a Facebook::Graph::Query object, which can be used to fetch and search data from Facebook.

Fetch a Facebook::Graph URI you already have.

uri

The URI to fetch. For example: https://graph.facebook.com/amazon

Returns a hash reference of an object from facebook. A quick way to grab an object from Facebook. These two statements are identical:

 my $sarah = $fb->fetch('sarahbownds');

 my $sarah = $fb->query->find('sarahbownds')->request->as_hashref;

id

An profile id like "sarahbownds" or an object id like 16665510298 for the Perl page.

Returns a Facebook::Graph::Picture object, which can be used to generate the URLs of the pictures of any object on Facebook.

id

An profile id like "sarahbownds" or an object id like 16665510298 for the Perl page.

Creates a Facebook::Graph::Publish::Post object, which can be used to publish data to a user's feed/wall.

Creates a Facebook::Graph::Publish::Photo object, which can be used to publish a photo to a user's feed/wall.

id

Optionally provide an object id to place it on. Requires that you have administrative access to that page/object.

Creates a Facebook::Graph::Publish::Checkin object, which can be used to publish a checkin to a location.

id

Optionally provide an user id to check in. Requires that you have administrative access to that user.

Creates a Facebook::Graph::Publish::Like object to tell everyone about a post you like.

id

The id of a post you like.

Creates a Facebook::Graph::Publish::Comment object that you can use to comment on a note.

id

The id of the post you want to comment on.

Creates a Facebook::Graph::Publish::Note object, which can be used to publish notes.
Creates a Facebook::Graph::Publish::Link object, which can be used to publish links.

Creates a Facebook::Graph::Publish::Event object, which can be used to publish events.

Creates a Facebook::Graph::Publish::PageTab object, which can be used to publish an app as a page tab.

id

Optionally provide an object id to place it on. Requires that you have administrative access to that page/object.

RSVP as 'maybe' to an event.

id

The id of an event.

RSVP as 'attending' to an event.

id

The id of an event.

RSVP as 'declined' to an event.

id

The id of an event.

A utility method to convert old sessions into access tokens that can be used with the Graph API. Returns an array reference of hash references of access tokens.

 [
   {
     "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "expires": 1271649600,
   },
   ...
 ]

See also Facebook::Graph::Session.

sessions

An array reference of session ids from the old Facebook API.

Allows the decoding of signed requests for canvas applications to ensure data passed back from Facebook isn't tampered with. You can read more about this at <http://developers.facebook.com/docs/authentication/canvas>.

$signed_request

A signature string passed from Facebook. To capture a signed request your app must be displayed within the Facebook canvas page and then you must pull the query parameter called "signed_request" from the query string.

NOTE: To get this passed to your app you must enable it in your migration settings for your app (<http://www.facebook.com/developers/>).

This module throws exceptions when it encounters a problem. It uses Ouch to throw the exception, and the Exception typically takes 3 parts: code, message, and a data portion that is the URI that was originally requested. For example:

 eval { $fb->call_some_method };
 if (kiss 500) {
   say "error: ". $@->message;
   say "uri: ".$@->data;
 }
 else {
   throw $@; # rethrow the error
 }

I still need to add publishing albums/photos, deleting of content, impersonation, and analytics to have a feature complete API. In addition, the module could use a lot more tests.

Any::Moose JSON AnyEvent::HTTP::LWP::UserAgent URI DateTime DateTime::Format::Strptime MIME::Base64::URLSafe Ouch

Digest::SHA is used for signed requests. If you don't plan on using the signed request feature, then you do not need to install Digest::SHA.

Repository
<http://github.com/rizen/Facebook-Graph>
Bug Reports
<http://github.com/rizen/Facebook-Graph/issues>

If you're looking for a fully featured Facebook client in Perl I highly recommend WWW::Facebook::API. It does just about everything, it just uses the old Facebook API.

JT Smith <jt_at_plainblack_dot_com>

Facebook::Graph is Copyright 2010 - 2012 Plain Black Corporation (<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
2014-09-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.