Package tipy :: Module minr :: Class GraphAPI
[hide private]
[frames] | no frames]

Class GraphAPI

source code

object --+
         |
        GraphAPI

A client for the Facebook Graph API.
See http://developers.facebook.com/docs/api for complete
documentation for the API.
The Graph API is made up of the objects in Facebook (e.g., people,
pages, events, photos) and the connections between them (e.g.,
friends, photo tags, and event RSVPs). This client provides access
to those primitive types in a generic way. For example, given an
OAuth access token, this will fetch the profile of the active user
and the list of the user's friends:
   graph = facebook.GraphAPI(access_token)
   user = graph.get_object("me")
   friends = graph.get_connections(user["id"], "friends")
You can see a list of all of the objects and connections supported
by the API at http://developers.facebook.com/docs/reference/api/.
You can obtain an access token via OAuth or by using the Facebook
JavaScript SDK. See
http://developers.facebook.com/docs/authentication/ for details.
If you are using the JavaScript SDK, you can use the
get_user_from_cookie() method below to get the OAuth access token
for the active user from the cookie saved by the SDK.

Instance Methods [hide private]
 
__init__(self, access_token=None, timeout=None, version=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
get_object(self, id, **args)
Fetchs the given object from the graph.
source code
 
get_objects(self, ids, **args)
Fetchs all of the given object from the graph.
source code
 
get_connections(self, id, connection_name, **args)
Fetchs the connections for given object.
source code
 
put_object(self, parent_object, connection_name, **data)
Writes the given object to the graph, connected to the given parent.
source code
 
put_wall_post(self, message, attachment={}, profile_id='me')
Writes a wall post to the given profile's wall.
source code
 
put_comment(self, object_id, message)
Writes the given comment on the given post.
source code
 
put_like(self, object_id)
Likes the given post.
source code
 
delete_object(self, id)
Deletes the object with the given ID from the graph.
source code
 
delete_request(self, user_id, request_id)
Deletes the Request with the given ID for the given user.
source code
 
put_photo(self, image, album_path='me/photos', **kwargs)
Upload an image using multipart/form-data.
source code
 
get_version(self)
Fetches the current version number of the Graph API being used.
source code
 
request(self, path, args=None, post_args=None, files=None, method=None)
Fetches the given path in the Graph API.
source code
 
fql(self, query)
FQL query.
source code
 
get_app_access_token(self, app_id, app_secret)
Get the application's access token as a string.
source code
 
get_access_token_from_code(self, code, redirect_uri, app_id, app_secret)
Get an access token from the "code" returned from an OAuth dialog.
source code
 
extend_access_token(self, app_id, app_secret)
Extends the expiration time of a valid OAuth access token.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, access_token=None, timeout=None, version=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

get_objects(self, ids, **args)

source code 

Fetchs all of the given object from the graph. We return a map from ID to object. If any of the IDs are invalid, we raise an exception.

put_object(self, parent_object, connection_name, **data)

source code 
Writes the given object to the graph, connected to the given parent.
For example,
    graph.put_object("me", "feed", message="Hello, world")
writes "Hello, world" to the active user's wall. Likewise, this
will comment on a the first post of the active user's feed:
    feed = graph.get_connections("me", "feed")
    post = feed["data"][0]
    graph.put_object(post["id"], "comments", message="First!")
See http://developers.facebook.com/docs/api#publishing for all
of the supported writeable objects.
Certain write operations require extended permissions. For
example, publishing to a user's feed requires the
"publish_actions" permission. See
http://developers.facebook.com/docs/publishing/ for details
about publishing permissions.

put_wall_post(self, message, attachment={}, profile_id='me')

source code 
Writes a wall post to the given profile's wall.
We default to writing to the authenticated user's wall if no
profile_id is specified.
attachment adds a structured attachment to the status message
being posted to the Wall. It should be a dictionary of the form:
    {"name": "Link name"
     "link": "http://www.example.com/",
     "caption": "{*actor*} posted a new review",
     "description": "This is a longer description of the attachment",
     "picture": "http://www.example.com/thumbnail.jpg"}

put_photo(self, image, album_path='me/photos', **kwargs)

source code 

Upload an image using multipart/form-data. image - A file object representing the image to be uploaded. album_path - A path representing where the image should be uploaded.

request(self, path, args=None, post_args=None, files=None, method=None)

source code 

Fetches the given path in the Graph API. We translate args to a valid query string. If post_args is given, we send a POST request to the given path with the given arguments.

fql(self, query)

source code 

FQL query. Example query: "SELECT affiliations FROM user WHERE uid = me()"

get_access_token_from_code(self, code, redirect_uri, app_id, app_secret)

source code 

Get an access token from the "code" returned from an OAuth dialog. Returns a dict containing the user-specific access token and its expiration date (if applicable).

extend_access_token(self, app_id, app_secret)

source code 

Extends the expiration time of a valid OAuth access token. See <https://developers.facebook.com/roadmap/offline-access-removal/ #extend_token>