The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Facebook::Graph::Query - Simple and fast searching and fetching of Facebook data.

VERSION

version 0.0500

SYNOPSIS

 my $fb = Facebook::Graph->new;
 
 my $perl_page = $fb->find('16665510298')
    ->include_metadata
    ->request
    ->to_hashref;
 
 my $sarah_bownds = $fb->find('sarahbownds')
    ->select_fields(qw(id name))
    ->request
    ->to_hashref;

 # this one would require an access token
 my $new_car_posts = $fb->query
    ->search('car', 'my_news')
    ->where_since('yesterday')
    ->request
    ->to_hashref;

DESCRIPTION

This module presents a programatic approach to building the queries necessary to search and retrieve Facebook data. It provides an almost SQL like way of writing queries using code. For example:

 my $results = $fb
    ->select_fields(qw(id name))
    ->search('Dave','user')
    ->where_since('yesterday')
    ->limit_results(25)
    ->request
    ->to_hashref;
    

The above query, if you were read it like text, says: "Give me the user ids and full names of all users named Dave that have been created since yesterday, and limit the result set to the first 25."

METHODS

find ( id )

Fetch a single item.

id

The unique id or object name of an object.

Example: For user "Sarah Bownds" you could use either her profile id sarahbownds or her object id 767598108.

search ( query, type )

Perform a keyword search on a group of items.

query

They keywords to search by.

type

One of the following types:

my_news

The current user's news feed (home page). Requires that you have an access_token so you know who the current user is.

post

All public posts.

user

All people.

page

All pages.

event

All events.

group

All groups.

limit_results ( amount )

The result set will only return a certain number of records when this is set. Useful for paging result sets. Returns $self for method chaining.

amount

An integer representing the number of records to be returned.

offset_results ( amount )

Skips ahead the result set by the amount. Useful for paging result sets. Is only applied when used in combination with limit_results. Returns $self for method chaining.

amount

An integer representing the amount to offset the results by.

include_metadata ( [ include ] )

Adds metadata to the result set including things like connections to other objects and the object type being returned. Returns $self for method chaining.

include

Defaults to 1 when the method is called, but defaults to 0 if the method is never called. You may set it specifically by passing in a 1 or 0.

select_fields ( fields )

Limit the result set to only include the specific fields if they exist in the objects in the result set. Returns $self for method chaining. May be called multiple times to add more fields.

fields

An array of fields you want in the result set.

Example: 'id', 'name', 'picture'

where_ids ( ids )

Limit the result set to these specifically identified objects. Returns $self for method chaining. May be called multiple times to add more ids.

ids

An array of object ids, object names, or URIs.

Example: 'http://www.thegamecrafter.com/', 'sarahbownds', '16665510298'

where_until ( date )

Include only records that were created before date. Returns $self for method chaining.

date

Anything accepted by PHP's strtotime function http://php.net/manual/en/function.strtotime.php.

where_since ( date )

Include only records that have been created since date. Returns $self for method chaining.

date

Anything accepted by PHP's strtotime function http://php.net/manual/en/function.strtotime.php.

uri_as_string ()

Returns a URI string based upon all the methods you've called so far on the query. Mainly useful for debugging. Usually you want to call request and have it fetch the data for you.

request ( [ uri ] )

Forms a URI string based on every method you've called so far, and fetches the data. Returns a Facebook::Graph::Response object.

uri

Optionally pass in your own URI string and all the other options will be ignored. This is mainly useful with metadata connections. See include_metadata for details.

LEGAL

Facebook::Graph is Copyright 2010 Plain Black Corporation (http://www.plainblack.com) and is licensed under the same terms as Perl itself.