5 """Facebook backend for Hermes, using the Graph API:
7 http://developers.facebook.com/docs/reference/api/
9 Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
10 Released under the Artistic Licence."""
13 # -----------------------------------------------------------------------
14 def __init__(self, oauth):
18 # -----------------------------------------------------------------------
19 def authenticate(self):
20 '''Authenticate the user with Facebook.'''
22 self._oauth.authorise('https://graph.facebook.com/oauth/authorize',
23 'https://graph.facebook.com/oauth/access_token',
24 {'scope': 'user_about_me,friends_about_me,user_birthday,friends_birthday,user_website,friends_website,user_work_history,friends_work_history'})
27 # -----------------------------------------------------------------------
29 '''Return the name of the authenticated user.'''
31 data = self._request('https://graph.facebook.com/me')
35 # -----------------------------------------------------------------------
36 def get_friends(self):
37 '''Return the full list of people being followed by the user.
39 The result is a list of users:
40 http://developers.facebook.com/docs/reference/api/user/'''
42 users = self._request('https://graph.facebook.com/me/friends', {'fields': 'id,name,link,birthday,website,picture'})['data']
45 user['picture'] = 'https://graph.facebook.com/%s/picture?type=large&access_token=%s' % (user['id'], self._oauth.get_access_token())
49 # -----------------------------------------------------------------------
50 def _request(self, url, args = None):
51 """Make an authenticated request to Facebook and check the
52 JSON response. Return the dictionary if no errors."""
54 json = self._oauth.request(url, args)
56 data = simplejson.loads(json)
58 raise Exception(data['error'])