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 def copy(data, from_key, to, to_key = None):
47 to[to_key] = data[from_key]
49 users = self._request('https://graph.facebook.com/me/friends', {'fields': 'id,name,link,birthday,website,picture', 'type': 'large'})
53 # -----------------------------------------------------------------------
54 def _request(self, url, args = None):
55 """Make an authenticated request to Facebook and check the
56 JSON response. Return the dictionary if no errors."""
58 json = self._oauth.request(url, args)
60 data = simplejson.loads(json)
62 raise Exception(data['error'])