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.