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.

classmethod parse(signed_request, application_secret_key)

Parse a signed request, returning a dictionary describing its payload.

user = None

A SignedRequest.User instance describing the user that generated the signed request.

data = None

A string describing the contents of the app_data query string parameter.

page = None

A SignedRequest.Page instance describing the Facebook page that the signed request was generated from.

generate()

Generate a signed request from this instance.

class User(id, age=None, locale=None, country=None, oauth_token=None)

A User instance 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 datetime instance describing when the access token will expire, or None if it won’t.

has_expired

A boolean describing whether the access token has expired.

issued_at = None

A datetime instance 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.

SignedRequest.User.has_authorized_application

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.OAuthToken instance describing an OAuth access token.

SignedRequest.User.profile_url

A string describing the URL to the user’s Facebook profile.

class SignedRequest.Page(id, is_liked=False, is_admin=False)

A Page instance 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.

Previous topic

Graph API

Next topic

Utilities

This Page