不,您可以使用 urlread 函数使用 Facebook 图形 API。您需要做的就是使用 Javascript 从用户那里获取访问令牌,FB 开发人员网站上有相关文档。这是一个如何使用 URL 库函数的示例
class Facebook(object):
def __init__(self, auth_token):
self.auth_token = auth_token
def load(self, method, user_id = 'me'):
raw = urlopen("https://graph.facebook.com/%s/%s/?access_token=%s" % (user_id, method, self.auth_token)).read()
data = loads(raw)
return data['data'] or []
def with_fields(self, method, user_id = 'me', fields = 'name,likes'):
raw = urlopen("https://graph.facebook.com/%s/%s/?fields=%s&access_token=%s" % (user_id, method, fields, self.auth_token)).read()
data = loads(raw)
return data['data'] or []
def likes(self, user_id = 'me'):
return self.with_fields('likes', user_id, 'name,category')
def me(self):
data = loads (urlopen("https://graph.facebook.com/me?fields=name&access_token=%s" % self.auth_token).read())
return data or {}
def expand(self, like):
data = loads (urlopen("https://graph.facebook.com/%s?access_token=%s" % (like['id'], self.auth_token)).read())
return data or {}
def friends(self, user_id = 'me'):
return self.load('friends', user_id)
def movies(self, user_id = 'me'):
return self.with_fields('movies', user_id)
def music(self, user_id = 'me'):
return self.with_fields('music', user_id)
def picture(self, user_id='me', size=None):
if size:
return "https://graph.facebook.com/%s/picture?access_token=%s&type=%s" % (user_id, self.auth_token, size)
return "https://graph.facebook.com/%s/picture?access_token=%s" % (user_id, self.auth_token)