2👍
✅
Right, pyfacebook
does not yet support required_permissions
for login
, but you can call (or rather, redirect to) authorize
manually. I’ve just written the following decorator for my purposes:
def require_permissions(*names):
"""Require extended permissions.
XXX: in theory, the facebook.require_login() decorator should support
this, but doesn't in pyfacebook yet."""
def decorator(fn):
required_perms = set(names)
def wrapper(request, *args, **kwargs):
fb = request.facebook
perms = set() if fb.ext_perms is None \
else set(fb.ext_perms.split(','))
if not required_perms.issubset(perms):
missing = required_perms.difference(perms)
url = fb.get_ext_perm_url(','.join(missing),
next='%s%s' % (fb.get_app_url(), request.path[1:]))
print url
return fb.redirect(url)
return fn(request, *args, **kwargs)
return wrapper
return decorator
You may have to tweak the value of next
as it is passed to get_ext_perm_url
, but this should otherwise be fine (works for me). Usage example:
@facebook.require_login()
@facebook.require_add()
@require_permissions('email', 'offline_access')
def index(request):
# ...
Source:stackexchange.com