NAME
Facebook::Graph::Query - Simple and fast searching and fetching of Facebook data.
VERSION
version 1.1203
SYNOPSIS
my $fb = Facebook::Graph->new;
my $perl_page = $fb->query->find('16665510298')
->include_metadata
->request
->as_hashref;
my $sarah_bownds = $fb->query->find('sarahbownds')
->select_fields(qw(id name))
->request
->as_hashref;
# this one would require an access token
my $new_years_posts = $fb->query
->from('posts')
->where_since('1 January 2011')
->where_until('2 January 2011')
->limit(25)
->date_format('U')
->request
->as_hashref;
# this one would require an access token
my $new_car_posts = $fb->query
->search('car', 'my_news')
->where_since('yesterday')
->request
->as_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
->as_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
.
from ( context )
If you prefer to search by keyword see the search
method.
context
One of the following contexts:
- 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.
search ( query, context )
Perform a keyword search on a group of items.
If you prefer not to search by keyword see the from
method.
query
They keywords to search by.
context
See the context
param in the from
method.
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.
date_format ( format )
The result set dates will be formatted in the defined formats. Specify the format by reference the PHP date format spec: http://php.net/manual/en/function.date.php. (eg. ->date_format('U')->) Useful for getting epoch for datatime. 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 - 2012 Plain Black Corporation (http://www.plainblack.com) and is licensed under the same terms as Perl itself.