Skip to content

Instantly share code, notes, and snippets.

@tzangms
Created February 8, 2013 07:41
Show Gist options
  • Select an option

  • Save tzangms/4737318 to your computer and use it in GitHub Desktop.

Select an option

Save tzangms/4737318 to your computer and use it in GitHub Desktop.
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