Created
February 8, 2013 07:41
-
-
Save tzangms/4737318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import urllib | |
| import json | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| class FacebookLike(object): | |
| def __init__(self, access_token, user_id): | |
| self.query = 'select object_id from like where user_id=%s' % user_id | |
| self.access_token = access_token | |
| def __iter__(self): | |
| params = urllib.urlencode({ | |
| 'q': self.query, | |
| 'access_token': self.access_token | |
| }) | |
| url = 'https://graph.facebook.com/fql?' + params | |
| r = requests.get(url) | |
| data = json.loads(r.content) | |
| items = data['data'] | |
| for item in items: | |
| r = requests.get('https://graph.facebook.com/' + str(item['object_id']) + '?access_token=' + self.access_token) | |
| if r.status_code != 200: | |
| logger.debug(r.content) | |
| data = json.loads(r.content) | |
| yield data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment