-
Notifications
You must be signed in to change notification settings - Fork 21
/
facebook.py
40 lines (27 loc) · 949 Bytes
/
facebook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Facebook OpenGraph API. Usage:
api = FacebookAPI()
r = api.call('/', ids='shazow,minecraft')
"""
from apiclient import APIClient
class FacebookError(Exception):
def __init__(self, type, message, response=None):
self.type = type
self.message = message
self.response = response
def __str__(self):
return "%s (%s)" % (self.type, self.message)
def __repr__(self):
return "%s(type=%s)" % (self.__class__.__name__, self.type)
class FacebookAPI(APIClient):
BASE_URL = 'https://graph.facebook.com/'
def _handle_response(self, response):
r = super(FacebookAPI, self)._handle_response(response)
has_error = r.get('error')
if not has_error:
return r
raise FacebookError(has_error['type'], has_error['message'], response=response)
if __name__ == '__main__':
api = FacebookAPI()
r = api.call('/', ids='shazow,minecraft')
print r