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')
)
class facepy.GraphAPI(oauth_token=False, url='https://graph.facebook.com', verify_ssl_certificate=True, appsecret=False, timeout=None, version=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, **data)

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.

  • data – Graph API parameters such as ‘main_page_id’ or ‘location_page_id’.

See Facebook’s Graph API documentation for an exhaustive list of parameters.

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='place', 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 only place since Graph API 2.0.

See Facebook’s Graph API documentation for an exhaustive list of options.