API Reference¶
This page contains specific information on the SDKs classes, methods and functions.
class facebook.GraphAPI¶
A client for the Facebook Graph API. The Graph API is made up of the objects or nodes in Facebook [e.g., people, pages, events, photos] and the connections or edges between them [e.g., friends, photo tags, and event RSVPs]. This client provides access to those primitive types in a generic way.
You can read more about Facebooks Graph API here.
Parameters
- access_token A string that identifies a user, app, or page and can be used by the app to make graph API calls. Read more about access tokens here.
- timeout - A float describing [in seconds] how long the client will be waiting for a response from Facebooks servers. See more here.
- version - A string describing the version of Facebooks Graph API to use. The default version is the oldest current version. It is used if the version keyword argument is not provided.
- proxies - A dict with proxy-settings that Requests should use. See Requests documentation.
- session - A Requests Session object.
- app_secret - A string containing the secret key of your app. If both access_token and app_secret are present this will be used to compute an application secret proof that will be sent on every API request.
Example
Methods¶
get_object¶
Returns the given object from the graph as a dict. A list of supported objects can be found here.
Parameters
- id A string that is a unique ID for that particular resource.
- **args [optional] - keyword args to be passed as query params
Examples
get_objects¶
Returns all of the given objects from the graph as a dict. Each given ID maps to an object.
Parameters
- ids A list containing IDs for multiple resources.
- **args [optional] - keyword args to be passed as query params
Examples
search¶
//developers.facebook.com/docs/places/search
Valid types are: place, placetopic
Parameters
- type A string containing a valid type.
- **args [optional] - keyword args to be passed as query params
Example
get_connections¶
Returns all connections for a given object as a dict.
Parameters
- id A string that is a unique ID for that particular resource.
- connection_name - A string that specifies the connection or edge between objects, e.g., feed, friends, groups, likes, posts. If left empty, get_connections will simply return the authenticated users basic information.
Examples
get_all_connections¶
Iterates over all pages returned by a get_connections call and yields the individual items.
Parameters
- id A string that is a unique ID for that particular resource.
- connection_name - A string that specifies the connection or edge between objects, e.g., feed, friends, groups, likes, posts.
put_object¶
Writes the given object to the graph, connected to the given parent.
Parameters
- parent_object A string that is a unique ID for that particular resource. The parent_object is the parent of a connection or edge. E.g., profile is the parent of a feed, and a post is the parent of a comment.
- connection_name - A string that specifies the connection or edge between objects, e.g., feed, friends, groups, likes, posts.
Examples
put_comment¶
Writes the given message as a comment on an object.
Parameters
- object_id - A string that is a unique id for a particular resource.
- message - A string that will be posted as the comment.
Example
put_like¶
Writes a like to the given object.
Parameters
- object_id - A string that is a unique id for a particular resource.
Example
put_photo¶
//developers.facebook.com/docs/graph-api/reference/user/photos#publish
Upload an image using multipart/form-data. Returns JSON with the IDs of the photo and its post.
Parameters
- image - A file object representing the image to be uploaded.
- album_path - A path representing where the image should be uploaded. Defaults to /me/photos which creates/uses a custom album for each Facebook application.
Examples
delete_object¶
Deletes the object with the given ID from the graph.
Parameters
- id - A string that is a unique ID for a particular resource.
Example
get_permissions¶
//developers.facebook.com/docs/graph-api/reference/user/permissions/
Returns the permissions granted to the app by the user with the given ID as a set.
Parameters
- user_id - A string containing a users unique ID.
Example
get_auth_url¶
//developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
Returns a Facebook login URL used to request an access token and permissions.
Parameters
- app_id - A string containing a Facebook application ID.
- canvas_url - A string containing the URL where Facebook should redirect after successful authentication.
- perms - An optional list of requested Facebook permissions.
Example