Django-friendface is a django application for interacting with Facebook. The goal is to have a complete implementation Facebook's API's in a django centric fashion and to support projects that have multiple Facebook Applications.
INSTALLED_APPS += ('friendface',)
Each application you want to use you need to setup in the django admin.
Once saved the application will request all of its details from Facebook.
{% load facebook %}
<a href="https://github.com/mediapop/django-friendface/blob/master/{% fburl 'my_app.views.index' %}">My view on Facebook!</a>
AUTHENTICATION_BACKENDS += ('friendface.auth.backends.FacebookBackend',)
This will cause newly authenticated users to also create a regular Django user.
Django will link to FacebookUser to the Users profile as facebook
. This means
that there needs to be a Profile on the User object.
class Profile(models.Model):
user = models.OneToOneField('contrib.auth.User')
facebook = models.OneToOneField('friendface.FacebookUser',
null=True,
blank=True)
MIDDLEWARE_CLASSES += (
'friendface.middleware.FacebookApplicationMiddleware',
'friendface.middleware.FacebookDecodingMiddleware',
'friendface.middleware.DisableCsrfProtectionOnDecodedSignedRequest',
'friendface.middleware.FacebookSignedRequestAuthenticationMiddleware',
)
Matches your request path with the Facebook
applications paths and loads that application. If there's more than one
application with the same path it will pick the most exact match (i.e. the
shorter URL.) and set the facebook_application
on the request
.
def my_fancy_view(request):
app = request.facebook_application
response = app.request('http://www.mediapop.co')
return HttpResponse(response['shares'])
Decodes the signed_request
and makes it accessible via request.FACEBOOK
Reads the user_id
from a decoded request and signs that user in.
friendface is prepared for testing both it's Javascript and Python components. Simply ensure that you got all Python requirements installed and that you got a recent version of node.js with npm installed. Then simply type:
$ make test
If necessary npm will install requirements for phantom.js.
If the request has mobile
set to True
then the
FacebookAppAuthMixin
will act like MobileView
and set the current
session as Facebook mobile. This means that when the user access the
app on http://apps.facebook.com then the user will be redirected to
the bare domain of the app. The current normal workflow goes like:
To get detection install a mobile detection middleware and make sure
it marks the as mobile = True
.
Install django-mobi and add it's middleware to our settings:
MIDDLEWARE_CLASSES += (
'mobi.middleware.MobileDetectionMiddleware'
)