Facebook open graph api implementation using the Django web framework in python

Overview

Django Facebook by Thierry Schellenbach (mellowmorning.com)

https://secure.travis-ci.org/tschellenbach/Django-facebook.png?branch=master https://pypip.in/d/django-facebook/badge.png

Status

Django and Facebook are both rapidly changing at the moment. Meanwhile, I'm caught up in a startup and don't have much spare time. The library needs a good round of testing against the latest python, django and facebook graph API. Contributions are strongly appreciated. Seriously, give github a try, fork and get started :)

News

  • django-facebook will be dropping support for django < 1.8 since django only supports versions 1.8 and above.

Demo & About

Django Facebook enables your users to easily register using the Facebook API. It converts the Facebook user data and creates regular User and Profile objects. This makes it easy to integrate with your existing Django application.

After registration Django Facebook gives you access to user's graph. Allowing for applications such as:

  • Open graph/ Timeline functionality
  • Seamless personalization
  • Inviting friends
  • Finding friends
  • Posting to a users profile

Updates and tutorials can be found on my blog mellowmorning

Features

  • Access the Facebook API, from:
    • Your website (Using javascript OAuth)
    • Facebook canvas pages (For building facebook applications)
    • Mobile (Or any other flow giving you a valid access token)
  • Django User Registration (Convert Facebook user data into a user model)
  • Store likes, friends and user data locally.
  • Facebook FQL access
  • OAuth 2.0 compliant
  • Automated reauthentication (For expired tokens)
  • Includes Open Facebook (stable and tested Python client to the graph API)

Documentation

Basics

Open Facebook API

Advanced

Contributing and Running tests

Tests are run from within the example project. You can run them yourself as follows:

install from git

facebook_example/manage.py test django_facebook

Vagrant

A vagrant development setup is included in the GIT repo. Assuming you have vagrant installed, simply type the following in your shell:

# First get a fresh Django-Facebook checkout
git clone [email protected]:tschellenbach/Django-facebook.git django-facebook

# Go to the directory:
cd django-facebook

# Time to start Vagrant (grab a cup of coffee after this command, it'll take a while) :)
vagrant up; vagrant provision

# Finally done?
vagrant ssh
python manage.py runserver 0:8000

To have a working Django Facebook example up and running at 192.168.50.42:8000/facebook/example/. For the facebook login to work simply map that ip to vagrant.mellowmorning.com (Since Facebook checks the domain)

You can run the test suite by typing:

python manage.py test django_facebook
Comments
  • What should be the Site URL in facebook app settings to work from localhost?

    What should be the Site URL in facebook app settings to work from localhost?

    I am trying to work with the example page (/facebook/example/) from localhost and I always get "Given URL is not permitted by the application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

    In my Site URL (Facebook app settings) I have this: http://127.0.0.1:8000/facebook/example/

    Is it possible to work from locahost? How?

    opened by xpanta 42
  • Facebook image doesn't seem to be storing

    Facebook image doesn't seem to be storing

    I could have sworn my facebook image was being stored until I started needing to make thumbnails. Doing user.get_profile().image returns:

    <ImageFieldFile: None>
    

    Attempting to get the url attribute throws the following error:

    ValueError: The 'image' attribute has no file associated with it.
    

    Any ideas what could be the problem?

    opened by dellis23 18
  • Error validating access token (Expired) ... Catch

    Error validating access token (Expired) ... Catch

    Hey there, working on a very simple Facebook app using Django-facebook. It simply authenticates to Facebook, list the users Albums, select a photo, save, done!

    Our code is below, but I just can't escape this error and log the user back in. The token expired after a small amount of time, which is fine but we need to allow them to log back in, just catching the error and redirecting them to the "Login" screen isn't helping.

    Any ideas would be amazing. Thanks guys

    Error

    OAuthException at / Error validating access token: Session has expired at unix time 1332396000. The current unix time is 1332459417.

    Login

    <form action="{% url facebook_connect %}?facebook_login=1" method="post">
        <input type="hidden" value="{{ request.path }}?album=facebook" name="next" />
        <a href="javascript:void(0);" class="facebook" onclick="F.connect(this.parentNode, ['publish_actions', 'user_photos']);">Register, login or connect with facebook</a>
    </form>
    

    Get Albums

    fb = get_persistent_graph(request)
    if fb.is_authenticated():       
        albums = fb.get("me/albums")["data"]
    

    And that's where it dies as it no longer has access to anything under "fb", so the albums JSON is empty, if printed it errors.

    opened by stateempire 16
  • Django 1.5

    Django 1.5 "new_user is None, note that backward compatability for the older versions of django registration has been dropped."

    I'm using Django 1.5 and I've tried both AUTH_PROFILE_MODULE = 'f2pgame.UserProfile' AUTH_PROFILE_MODULE = 'django_facebook.FacebookProfile'.

    I do not understand what this error means since I'm attempting to use userena. Could it be that django-facebook has not been configured correctly to use userena?

    I've follow the example as closely as I could. Here are the important parts of settings.py:

    INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_facebook', 'open_facebook', 'f2pgame', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )

    TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.core.context_processors.request', 'django.contrib.messages.context_processors.messages', 'django_facebook.context_processors.facebook', )

    django-facebook config

    FACEBOOK_APP_ID = '433156246759817' FACEBOOK_APP_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXX' FACEBOOK_STORE_LIKES = False FACEBOOK_STORE_FRIENDS = False FACEBOOK_LOGIN_DEFAULT_REDIRECT = '/' USERENA_SIGNIN_REDIRECT_URL = '/' FACEBOOK_REGISTRATION_BACKEND = 'django_facebook.registration_backends.UserenaBackend'

    AUTH_PROFILE_MODULE = 'f2pgame.UserProfile'

    AUTH_PROFILE_MODULE = 'django_facebook.FacebookProfile'

    userena config

    from django.conf import settings

    USERENA_ACTIVATION_REQUIRED = getattr(settings, 'USERENA_ACTIVATION_REQUIRED', False) USERENA_ACTIVATED = getattr(settings, 'USERENA_ACTIVATED', 'ALREADY_ACTIVATED')

    ACCOUNT_ACTIVATION_DAYS = 0

    ANONYMOUS_USER_ID = 1 LOGIN_REDIRECT_URL = '/' LOGIN_URL = '/accounts/signin/' LOGOUT_URL = '/accounts/signout/'

    INSTALLED_APPS += ( 'userena', 'guardian', 'easy_thumbnails', )

    AUTHENTICATION_BACKENDS = ( 'django_facebook.auth_backends.FacebookBackend', 'django.contrib.auth.backends.ModelBackend', )

    EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'

    opened by cdelguercio 15
  • Ability to post photos and videos : multipart/form-data

    Ability to post photos and videos : multipart/form-data

    Facebook require multipart/form-data as type for "source" parameter. https://developers.facebook.com/docs/reference/api/page/#photos

    photo = open("picture.png", "rb")
    fb_api.set("me/photos", source=photo, message="Blabla ...", published=False)
    photo.close()
    

    Code largely inspired from https://github.com/feinheit/django-facebook-graph

    opened by BenoitNorrin 15
  • Python 3 compatibility

    Python 3 compatibility

    Hi, i had to change all the catched exception from : ", e" to "as e"

    example open_facebook\api.py L179 :

    except (urllib2.HTTPError,), e:
    

    into :

    except (urllib2.HTTPError,) as e:
    

    this syntax works for python 2 too : http://docs.python.org/2/tutorial/errors.html

    opened by neokeats 14
  • Add Python 3 compatibility

    Add Python 3 compatibility

    Hi,

    This PR is initiation for Python 3 support. I hope this will allow a Py3 experimental release.

    I tried to follow http://python3porting.com and https://docs.djangoproject.com/en/dev/topics/python3/ and it uses six compatibility library.

    All the tests are passing in both 2 and 3, except few glitches. Mainly, tests with 'assertRedirects' fail because in Python 3 version, the response redirect url is correct but parameters are not in order. I have only used redirect status code for Py3 for now, hoping that others or you might know better about the issue.

    The other notable issue was, while running tests on Py3, it complains about database table name. I am not sure exactly why, thus I set the db name FACEBOOK_OG_SHARE_DB_TABLE = 'django_facebook_open_graph_share' and it's working fine.

    Please review :)

    opened by chhantyal 12
  • 'AnonymousUser' object has no attribute 'backend'

    'AnonymousUser' object has no attribute 'backend'

    Hi,

    When I log in with the facebook button (javascript pop up), i get the following error message:

            AttributeError at /facebook/connect/
           'AnonymousUser' object has no attribute 'backend'
           Exception Type:  AttributeError
           Exception Value: 'AnonymousUser' object has no attribute 'backend'
           Exception Location:  /Users/marc-antoinelacroix/virtualenv/lib/python2.7/site-packages/django/utils/functional.py in inner,   line 185
    

    I read that it could be due to an incompatibility with django-registration, so I tried to delete:

     FACEBOOK_REGISTRATION_BACKEND = 'registration.backends.default.DefaultBackend'
    

    from my INSTALL_APPS. I still get the same error but now only the first time a user logs in. The second time it redirects the user to a registration form and indicates "This email address is already in use".

    Now I don't know what to do to solve this problem.

    Thank you for your help!

    opened by Marcolac 11
  • Problem AUTH_USER_MODEL set to 'member.FacebookUser'

    Problem AUTH_USER_MODEL set to 'member.FacebookUser'

    AUTH_USER_MODEL = 'member.FacebookUser' is returning the error: django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'member.FacebookUser' that has not been installed

    I'm working with the following configuration:

    Django==1.5.1
    django-facebook==5.1.1
    
    opened by filipeximenes 10
  • pip install django_facebook

    pip install django_facebook

    Downloading/unpacking django-facebook Running setup.py egg_info for package django-facebook Traceback (most recent call last): File "", line 14, in File "/Users/anujacharya/virtualenvs/facebook/build/django-facebook/setup.py", line 4, in from django_facebook import version, maintainer, email File "django_facebook/init.py", line 31, in from django_facebook.api import get_persistent_graph File "django_facebook/api.py", line 3, in from django_facebook import settings as facebook_settings File "django_facebook/settings.py", line 5, in FACEBOOK_APP_ID = getattr(settings, 'FACEBOOK_APP_ID', None) File "/Users/anujacharya/virtualenvs/facebook/lib/python2.7/site-packages/django/conf/init.py", line 52, in getattr self._setup(name) File "/Users/anujacharya/virtualenvs/facebook/lib/python2.7/site-packages/django/conf/init.py", line 45, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting FACEBOOK_APP_ID, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. Complete output from command python setup.py egg_info: Traceback (most recent call last):

    File "", line 14, in

    File "/Users/anujacharya/virtualenvs/facebook/build/django-facebook/setup.py", line 4, in

    from django_facebook import __version__, __maintainer__, __email__
    

    File "django_facebook/init.py", line 31, in

    from django_facebook.api import get_persistent_graph
    

    File "django_facebook/api.py", line 3, in

    from django_facebook import settings as facebook_settings
    

    File "django_facebook/settings.py", line 5, in

    FACEBOOK_APP_ID = getattr(settings, 'FACEBOOK_APP_ID', None)
    

    File "/Users/anujacharya/virtualenvs/facebook/lib/python2.7/site-packages/django/conf/init.py", line 52, in getattr

    self._setup(name)
    

    File "/Users/anujacharya/virtualenvs/facebook/lib/python2.7/site-packages/django/conf/init.py", line 45, in _setup

    % (desc, ENVIRONMENT_VARIABLE))
    

    django.core.exceptions.ImproperlyConfigured: Requested setting FACEBOOK_APP_ID, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

    opened by anujacharya1 10
  • Storing Access Token

    Storing Access Token

    In connect.py, I see code that will store the user's access token:

    if not graph.expires and graph.access_token != profile.access_token

    What do I need to set to prevent graph.expires from being true? I need the user's access token so I can post when they're offline. As such, I've put the following in my settings.py:

    FACEBOOK_DEFAULT_SCOPE = ['email', 'user_about_me', 'user_birthday', 'publish_stream', 'publish_actions', 'offline_access']

    Is there another setting I need to add or something I need in my app at Facebook?

    opened by tclancy 10
  • Setuptools v59 compliance

    Setuptools v59 compliance

    Setuptools description fields are intended to be only 1 line (see: https://setuptools.pypa.io/en/latest/references/keywords.html).

    This is now mandated in Setuptools v59, which has been breaking some build processes.

    This PR fixes the description length, and moves the more verbose description to the Readme.

    See this issue for more context: https://github.com/pypa/setuptools/issues/2893

    opened by aphi 1
  • docs: fix simple typo, rsponse -> response

    docs: fix simple typo, rsponse -> response

    There is a small typo in docs/docs_env/Lib/site-packages/pip-1.0-py2.5.egg/pip/download.py.

    Should read response rather than rsponse.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 0
  • cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'

    cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'

    python_2_unicode_compatible is not available on Django 3, you should use from six import python_2_unicode_compatible instead of from django.utils.six import python_2_unicode_compatible on django_facebook/models.py

    opened by daironigr 0
  • Can't Install it with Vagrant

    Can't Install it with Vagrant

    Hi

    I'm trying to install it as written in Read.Me :

    First get a fresh Django-Facebook checkout `git clone [email protected]:tschellenbach/Django-facebook.git django-facebook

    Go to the directory: cd django-facebook

    Time to start Vagrant (grab a cup of coffee after this command, it'll take a while) :) vagrant up; vagrant provision

    Finally done? vagrant ssh python manage.py runserver 0:8000

    However With Vagrant 2.1.2 and VirtualBox on Mac OS X 10.11.6 (El Capitan) I can't make it : vagrant up; vagrant provision

    It says : An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again.

    Failed to connect to hashicorp-files.hashicorp.com port 443: Operation timed out There were warnings and/or errors while loading your Vagrantfile for the machine 'local_dev-0'.

    Any suggestions ?

    opened by thomakl 0
Owner
Thierry Schellenbach
Author Stream-Framework, Founder/CEO getstream.io (Techstars NYC)
Thierry Schellenbach
Python SDK for Facebook's Graph API

Facebook Python SDK This client library is designed to support the Facebook Graph API and the official Facebook JavaScript SDK, which is the canonical

Mobolic 2.7k Nov 22, 2022
An unofficial API for lyricsfreak.com using django and django rest framework.

An unofficial API for lyricsfreak.com using django and django rest framework.

Hesam Norin 1 Feb 9, 2022
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Harun Mbaabu Mwenda 46 Sep 1, 2022
fbchat - Facebook Messenger for Python

A powerful and efficient library to interact with Facebook's Messenger, using just your email and password.

null 1.1k Nov 9, 2022
A simple Facebook Account generator, written in python (needs different Email so Accounts do not get banned)

FacebookAccountGenerator FAB is a Facebook-Account generating script, written in python Installation Use the package manager pip to install selenium p

MrOverload 5 Oct 8, 2022
Facebook fishing on telegram bot

Facebook-fishing Facebook fishing on telegram bot تثبيت الاداة pkg update -y pkg upgrade -y pkg install git -y pkg install python -y git clone https:/

sadamalsharabi 7 Oct 18, 2022
Brute Force Attack On Facebook Accounts

Brute Force Attack On Facebook Accounts For Install: pkg install update && pkg upgrade -y pkg install python pip install requests pip install mechani

MK X Shaon 1 Oct 30, 2021
Bot facebook

botfb Bot facebook Login via cookies cara install $pkg update && pkg upgrade $pkg install git python $git clone https://github.com/Ainx-BOT/botfb $cd

Fahmi Dev 11 Sep 2, 2022
Auto like & auto followers facebook

Auto like & auto followers facebook

Fahmi Dev 22 Nov 1, 2022
Script Crack Facebook, and Instagram 🚶‍♂

in-mbf Script Crack Facebook, and Instagram ??‍♂ Bukti Install Script $ pkg update && pkg upgrade $ pkg install git $ pkg install python2 $ pip2 insta

Yumasaa 5 Dec 27, 2021
📖 GitHub action schedular (cron) that posts a Hadith every hour on Twitter & Facebook.

Hadith Every Hour ?? A bot that posts a Hadith every hour on Twitter & Facebook (Every 3 hours for now to avoid spamming) Follow on Twitter @HadithEve

Ananto 13 Nov 1, 2022
A multi-password‌ cracking tool that can help you hack facebook accounts very quickly

FbCracker This is a multi-password‌ cracking tool that can help you hack facebook accounts very quickly. Facebook Hacking Tool Installation On Termux

ReD H4CkeR 9 Nov 16, 2022
wrapper for facebook messenger

pyfacebook pyfacebook library for python. Requirements common Help Got a question? File a GitHub issue. Contributing Bug Reports & Feature Requests Pl

Luis Mayta 3 Nov 12, 2021
SEBUAH TOOLS CRACK FACEBOOK & INSTAGRAM DENGAN FITUR YANGMENDUKUNG

SEBUAH TOOLS CRACK FACEBOOK & INSTAGRAM DENGAN FITUR YANGMENDUKUNG

Jeeck X Nano 1 Dec 27, 2021
Facebook Clooning Tool BD...

Facebook Clooning Tool BD...

Ariyan Ahmed Mamun 2 Feb 16, 2022
A bot to share Facebook posts.

bot_share_facebook a bot to share Facebook posts. install & clone untuk menjalankan anda bisa melalui terminal contohnya termux, cmd, dan terminal lai

Muhammad Latif Harkat 6 Aug 10, 2022
DevSecOps pipeline for Python based web app using Jenkins, Ansible, AWS, and open-source security tools and checks.

DevSecOps pipeline for Python Web App A Jenkins end-to-end DevSecOps pipeline for Python web application, hosted on AWS Ubuntu 20.04 Note: This projec

Devanshu Vashishtha 4 Aug 15, 2022
A Python script to create customised Spotify playlists using the JSON, Spotipy Library and Spotify Web API, based on seed tracks in your history.

A Python script to create customised Spotify playlists using the JSON, Spotipy Library and Spotify Web API, based on seed tracks in your history.

Youngseo Park 1 Feb 1, 2022
Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API.

Tg_PHub_Bot Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API. OS Support All linu

TheProgrammerCat 13 Oct 21, 2022