Signed requests¶
You may parse signed requests using the
SignedRequest class:
from facepy import SignedRequest
# Parse a signed request into a Python dict
signed_request_data = SignedRequest.parse(signed_request, facebook_application_secret_key)
# Get a SignedRequest object
signed_request = SignedRequest(signed_request, facebook_application_secret_key)
# Print the Facebook ID of the user that generated the signed request
print signed_request.user.id
# Print the OAuth access token for the user that generated the signed request
print signed_request.oauth_token.token
# Reverse-engineer the signed request
signed_request.generate(facebook_application_secret_key)
-
class
facepy.SignedRequest(signed_request=None, application_secret_key=None, application_id=None)¶ Facebook uses “signed requests” to communicate with applications on the Facebook platform. See Facebook’s documentation on authentication for more information.
-
class
Page(id, is_liked=False, is_admin=False)¶ A
Pageinstance represents a Facebook page.-
id= None¶ An integer describing the page’s Facebook ID.
-
is_admin= None¶ A bolean describing whether or nor the user is an administrator of the page.
-
is_liked= None¶ A boolean describing whether or not the user likes the page.
-
url¶ A string describing the URL to the page.
-
-
class
SignedRequest.User(id, age=None, locale=None, country=None, oauth_token=None)¶ A
Userinstance represents a Facebook user.-
class
OAuthToken(token, issued_at, expires_at)¶ An OAuth token represents an access token that may be used to query Facebook’s Graph API on behalf of the user that issued it.
-
expires_at= None¶ A
datetimeinstance describing when the access token will expire, orNoneif it won’t.
-
has_expired¶ A boolean describing whether the access token has expired.
-
issued_at= None¶ A
datetimeinstance describing when the access token was issued.
-
token= None¶ A string describing the access token.
-
-
SignedRequest.User.age= None¶ A range describing the user’s age.
-
SignedRequest.User.country= None¶ A string describing the user’s country.
A boolean describing whether the user has authorized the application.
-
SignedRequest.User.id= None¶ An integer describing the user’s Facebook ID.
-
SignedRequest.User.locale= None¶ A string describing the user’s locale.
-
SignedRequest.User.oauth_token= None¶ A
SignedRequest.User.OAuthTokeninstance describing an OAuth access token.
-
SignedRequest.User.profile_url¶ A string describing the URL to the user’s Facebook profile.
-
class
-
SignedRequest.data= None¶ A string describing the contents of the
app_dataquery string parameter.
-
SignedRequest.generate()¶ Generate a signed request from this instance.
-
SignedRequest.page= None¶ A
SignedRequest.Pageinstance describing the Facebook page that the signed request was generated from.
-
classmethod
SignedRequest.parse(signed_request, application_secret_key)¶ Parse a signed request, returning a dictionary describing its payload.
-
SignedRequest.user= None¶ A
SignedRequest.Userinstance describing the user that generated the signed request.
-
class