如何为facebook api创建自定义模型

时间:2013-05-16 13:33:52

标签: python django facebook-graph-api python-2.7

上下文:Facebook图形API,Django,Python 2.7

我想在python中使用facebook图形api(没关系),而且我正在学习这种语言。

我想使用models.py中的用户信息从facebook自动生成响应,将其逐个传递给facebook API,获取信息并更新数据库。但这需要自动运行。 目标是收集统计信息(因此用户不需要每次都更新,并且不会因请求而使服务器过载,这就是为什么我希望脚本在后端自动运行)。

示例:

用户有一个页面(一个或多个),他想获得它的属性: 所以我们知道页面的名称,因为用户通过django的forms.py添加,但我想自动传递信息,以便我们可以用它制作图表(喜欢,关注,......)

这是我的models.py

 class FacebookPage(models.Model):
        user_property = models.OneToOneField(User)
        name = models.CharField(max_length=150)
        def __unicode__(self):
            return self.name


class FacebookPageUpdate(FacebookPage):
        page_link = models.URLField()
        page_id = models.BigIntegerField()
        category = models.CharField(max_length=200)
        likes = models.BigIntegerField()
        new_like = models.IntegerField()
        talking_about_count = models.BigIntegerField()
        update_date = models.DateTimeField(auto_now=True)
        is_community_page = models.BooleanField()
        is_published = models.BooleanField()
        checkins = models.IntegerField()
        username = models.CharField(max_length=150)

这是我在python中编写的内容

from facebi.connect import token

graph = facebook.GraphAPI(token)
### the object_name is the name of the page from the models.PY    
datas = graph.get_object(object_name)  

#### Get Values from API page Return 

page_id = datas['id']
page_link = datas['link']
name = datas['name']
username = datas['username']
category = datas['category']
likes = datas['likes']
new_likes = datas['new_like_count']
talking_about_count = datas['talking_about_count']
is_community_page = datas['is_community_page']
is_published = datas['is_published']
checkins = datas['checkins']

但是现在我卡住了,我不知道如何将它逐个传递给对方并更新django数据库。

感谢您的帮助

于连

0 个答案:

没有答案