Models

class django_facebook.models.BaseFacebookModel(*args, **kwargs)[source]

Abstract class to add to your profile or user model. NOTE: If you don’t use this this abstract class, make sure you copy/paste the fields in.

extend_access_token()[source]

https://developers.facebook.com/roadmap/offline-access-removal/ We can extend the token only once per day Normal short lived tokens last 1-2 hours Long lived tokens (given by extending) last 60 days

The token can be extended multiple times, supposedly on every visit

get_offline_graph()[source]

Returns a open facebook graph client based on the access token stored in the user’s profile

get_user()[source]

Since this mixin can be used both for profile and user models

get_user_id()[source]

Since this mixin can be used both for profile and user_id models

open_graph_new_token_required[source]

Shows if we need to (re)authenticate the user for open graph sharing

refresh()[source]

Get the latest version of this object from the db

update_access_token(new_value)[source]

Updates the access token

Example:

# updates to 123 and sets new_token_required to False
profile.update_access_token(123)
Parameters:new_value – The new value for access_token
django_facebook.models.BaseFacebookProfileModel

alias of BaseFacebookModel

class django_facebook.models.BaseModel(*args, **kwargs)[source]

Stores the fields common to all incentive models

class django_facebook.models.BaseModelMetaclass[source]

Cleaning up the table naming conventions

class django_facebook.models.CreatedAtAbstractBase(*args, **kwargs)[source]

Stores the fields common to all incentive models

save(*args, **kwargs)[source]

Allow for auto clean support

class django_facebook.models.FacebookCustomUser(*args, **kwargs)[source]

The django 1.5 approach to adding the facebook related fields

class django_facebook.models.FacebookLike(*args, **kwargs)[source]

Model for storing all of a users fb likes

class django_facebook.models.FacebookModel(*args, **kwargs)[source]

the image field really destroys the subclassability of an abstract model you always need to customize the upload settings and storage settings

thats why we stick it in a separate class

override the BaseFacebookProfile if you want to change the image

class django_facebook.models.FacebookProfile(*args, **kwargs)[source]

Not abstract version of the facebook profile model Use this by setting AUTH_PROFILE_MODULE = ‘django_facebook.FacebookProfile’

django_facebook.models.FacebookProfileModel

alias of FacebookModel

class django_facebook.models.FacebookUser(*args, **kwargs)[source]

Model for storing a users friends

class django_facebook.models.OpenGraphShare(*args, **kwargs)[source]

Object for tracking all shares to Facebook Used for statistics and evaluating how things are going

I recommend running this in a task Example usage:

from user.models import OpenGraphShare
user = UserObject
url = 'http://www.fashiolista.com/'
kwargs = dict(list=url)

share = OpenGraphShare.objects.create(
    user = user,
    action_domain='fashiolista:create',
    content_object=self,
)
share.set_share_dict(kwargs)
share.save()
result = share.send()

Advanced usage:

share.send()
share.update(message='Hello world')
share.remove()
share.retry()

Using this model has the advantage that it allows us to

  • remove open graph shares (since we store the Facebook id)
  • retry open graph shares, which is handy in case of
    • updated access tokens (retry all shares from this user in the last facebook_settings.FACEBOOK_OG_SHARE_RETRY_DAYS)
    • Facebook outages (Facebook often has minor interruptions, retry in 15m, for max facebook_settings.FACEBOOK_OG_SHARE_RETRIES)
exception_requires_new_token(e, graph)[source]

Determines if the exceptions is something which requires us to ask for a new token. Examples are:

Error validating access token: Session has expired at unix time 1350669826. The current unix time is 1369657666.

(#200) Requires extended permission: publish_actions (error code 200)

update(data, graph=None)[source]

Update the share with the given data

django_facebook.models.validate_settings()[source]

Checks our Facebook and Django settings and looks for common errors