Graph API¶
You may interact with Facebook’s Graph API using the GraphAPI
class:
from facepy import GraphAPI
graph = GraphAPI(access_token)
# Get my latest posts
graph.get('me/posts')
# Post a photo of a parrot
graph.post(
path = 'me/photos',
source = open('parrot.jpg')
)
# Make a FQL query
graph.fql('SELECT name FROM user WHERE uid = me()')
# Make a FQL multiquery
graph.fql({
'rsvp_status': 'SELECT uid, rsvp_status FROM event_member WHERE eid=12345678',
'details': 'SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #rsvp_status)'
}
-
class
facepy.
GraphAPI
(oauth_token=False, url='https://graph.facebook.com', verify_ssl_certificate=True, appsecret=False, timeout=None)¶ -
batch
(requests)¶ Make a batch request.
Parameters: requests – A list of dictionaries with keys ‘method’, ‘relative_url’ and optionally ‘body’. Yields a list of responses and/or exceptions.
-
delete
(path, retry=3)¶ Delete an item in the Graph API.
Parameters: - path – A string describing the path to the item.
- retry – An integer describing how many times the request may be retried.
-
fql
(query, retry=3)¶ Use FQL to powerfully extract data from Facebook.
Parameters: - query – A FQL query or FQL multiquery ({‘query_name’: “query”,...})
- retry – An integer describing how many times the request may be retried.
See Facebook’s FQL documentation for an exhaustive list of details.
-
get
(path='', page=False, retry=3, **options)¶ Get an item from the Graph API.
Parameters: - path – A string describing the path to the item.
- page – A boolean describing whether to return a generator that iterates over each page of results.
- retry – An integer describing how many times the request may be retried.
- options – Graph API parameters such as ‘limit’, ‘offset’ or ‘since’.
Floating-point numbers will be returned as
decimal.Decimal
instances.See Facebook’s Graph API documentation for an exhaustive list of parameters.
-
post
(path='', retry=0, **data)¶ Post an item to the Graph API.
Parameters: - path – A string describing the path to the item.
- retry – An integer describing how many times the request may be retried.
- data – Graph API parameters such as ‘message’ or ‘source’.
See Facebook’s Graph API documentation for an exhaustive list of options.
-
search
(term, type, page=False, retry=3, **options)¶ Search for an item in the Graph API.
Parameters: - term – A string describing the search term.
- type – A string describing the type of items to search for.
- page – A boolean describing whether to return a generator that iterates over each page of results.
- retry – An integer describing how many times the request may be retried.
- options – Graph API parameters, such as ‘center’ and ‘distance’.
Supported types are
post
,user
,page
,event
,group
,place
andcheckin
.See Facebook’s Graph API documentation for an exhaustive list of options.
-