utils.py 600 B

12345678910111213141516171819202122
  1. import json, urllib
  2. # TODO: Redo all this, it is not really used except on one place
  3. def graph_api_url(fb_request, user=None, token=False):
  4. """
  5. Format Facebook Graph API URL.
  6. """
  7. param = ''
  8. if user and token:
  9. param = '?access_token=%s' % user.facebook_access_token
  10. results = 'https://graph.facebook.com/%s/%s' % (fb_request, param)
  11. return results
  12. def valid_token(user):
  13. """
  14. Check to see if a user's Facebook token is still valid.
  15. """
  16. data = json.load(urllib.urlopen(graph_api_url('me', user, token=True)))
  17. return 'error' not in data