Most of the Facebook examples are written in PHP and unfortunately for us they always seem so damn simple. I think the Python libraries should allow you to write more elegant code and the new version of Django Facebook let’s you do just that.
Much of the new found simplicity comes from the facebook_required decorator. This decorator is similar to login_required, but instead checks the Facebook permissions given to you. Writing the input of a form to someone’s wall is now as simple as this:
@facebook_required(scope='publish_stream')
def wall_post(request):
fb = get_persistent_graph(request)
message = request.POST.get('message')
fb.set('me/feed', message=message)
messages.info(request, 'Posted the message to your wall')
return next_redirect(request)
Another example would be uploading some photos to a user’s timeline:
@facebook_required(scope='publish_stream,user_photos')
def image_upload(request):
fb = get_persistent_graph(request)
pictures = request.POST.getlist('pictures')
for picture in pictures:
fb.set('me/photos', url=picture, message='the writing is one The '
'wall image %s' % picture)
messages.info(request, 'The images have been added to your profile!')
return next_redirect(request)
As you can see the syntax is very straightforward. You no longer have any technical excuse against integrating Facebook.
More examples and installation instructions can be found on Django Facebook’s github.
Messages responded on 24 Oct 2011 at 6:42 am #
Awesome logic! enhanced my skills!@bose
Thierry Schellenbach responded on 24 Oct 2011 at 10:22 am #
There are still some bugs with the session storage in combination with the redirect_uri.
Should be resolved in the coming days.
Alejandro K. responded on 27 Jan 2012 at 5:51 pm #
Hey Thierry. First of all thanks for sharing this. I’m trying to integrate your django Facebook into a website. I’m relatively new to the whole django/python (and facebook development) stuff.
I followed your instructions, installed everything but when I try to run the example project I get:
(jangoface)root@alek-laptop:/home/alek/youbloom/tschellenbach-Django-facebook-6d1e7a9/facebook_example# python manage.py runserver
Traceback (most recent call last):
File “manage.py”, line 2, in
from django.core.management import execute_manager
ImportError: No module named django.core.management
as you see it is not finding the django.core.management module. I wanted to let you know just in case there is something related to the package, though chances are I did something wrong. Do you provide any king of support for startup projects implementing this?
thanks a lot.
Ale K.