Code Monkey home page Code Monkey logo

fandjango-example's Introduction

Fandjango Example

This repository consists of a sample Facebook application powered by the Fandjango library and a walkthrough to replicate it.

Walkthrough

Register a Facebook application

First of all, we'll need to register a new application with the Facebook platform. To do so, go to facebook.com/developers and create your application. Once you have convinced Facebook that you are in fact human, you'll be presented with a daunting number of options. Don't worry, though; they're all optional and we only need to configure two of them right now:

  • App namespace - The URL you'd like your application to be accessed from, e.g. http://apps.facebook.com/myapp.
  • Canvas URL - The URL that Facebook may load your application from, e.g. http://myserver.com.

Create a new Django project

Next, create a new Django project and install Fandjango:

$ django-admin.py startproject myfacebookapplication
$ pip install fandjango

Add fandjango to INSTALLED_APPS in your settings file.

Configure Fandjango

Fandjango needs some configuration. Specifically, you need to add its middleware to your middleware classes and specify your application's id, secret key and namespace (all of which can be found on facebook.com/developers) in your settings file:

FACEBOOK_APPLICATION_ID = 181259711925270
FACEBOOK_APPLICATION_SECRET_KEY = '214e4cb484c28c35f18a70a3d735999b'
FACEBOOK_APPLICATION_NAMESPACE = 'myapp'

MIDDLEWARE_CLASSES = [
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'fandjango.middleware.FacebookMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
]

Finally, synchronize your database to install Fandjango's models:

$ python manage.py syncdb

Note: If you're using Django's built-in CSRF protection middleware, you need to make sure Fandjango's middleware precedes it. Otherwise, Facebook's requests to your application will qualify cross-site request forgeries.

Develop the application

# urls.py

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'fandjangoexample.views.home', name='home'),
)

# views.py

from django.http import HttpResponse
from fandjango.decorators import facebook_authorization_required

@facebook_authorization_required
def home(request):
    return HttpResponse('Hello, %s' % request.facebook.user.first_name)

Sit back and enjoy

That's it! You have created a Facebook application that authorizes and greets its users. Navigate to your application's canvas URL to have a closer look at your new marvel of technology.

Where do I go from here?

You should read the documentation and browse the source code.

fandjango-example's People

Contributors

jgorset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fandjango-example's Issues

oauth token longer than 255 characters

Hi,

We have had a couple of cases were the OAuth token is longer than 255 characters and causes the following;

Traceback (most recent call last):
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/core/handlers/base.py", line 89, in get_response
    response = middleware_method(request)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/fandjango/middleware.py", line 113, in process_request
    oauth_token = oauth_token
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/manager.py", line 138, in create
    return self.get_query_set().create(**kwargs)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/query.py", line 360, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/base.py", line 553, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/query.py", line 1436, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 791, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/home/www/mymoapp_env/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
    return self.cursor.execute(query, args)
DatabaseError: value too long for type character varying(255)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.