[英]Count likes on a Facebook post using Python+Facebook Graph API
[英]Facebook API Python - Likes Per Month?
我正在尝试创建一个应用程序,该应用程序将在Facebook上获得用户的“每月赞”。 我从未使用过Facebook API,而且似乎找不到如何做自己想做的好教程。
例如, 此页面具有URL,它将使我能够访问用户墙的JSON数据。 太酷了,但是如何在程序和应用程序中获取这些信息? 我已经在heroku上设置了基本应用程序,我将继续使用它。
致电/me/posts
,浏览分页数据并设置条件以基于created_time
存储点created_time
。
尽管如果有人回过头来开始喜欢旧帖子,那么所有这些都可能会出现偏差。 因此,这完全取决于您要如何定义每月的赞数
http://developers.facebook.com/docs/reference/api/user/#posts
您可以从使用像facepy这样的简单库开始
from facepy import GraphAPI
graph = GraphAPI('your_access_token_goes_here')
pages = graph.get("me/posts", page=True)
for page in pages:
// do something with page["data"] like drop the likes in a month array
我希望它还为时不晚,但是您可以实现以下功能:
from facepy import GraphAPI
graph = GraphAPI('your_access_token_goes_here')
pages = graph.get("me/posts", page=True)
getLikes(pages['posts']['data'])
def getLikes(this):
"""
Params- Takes in a page full of posts in the format- Eg. pages['posts']['data']
Returns- Total number of likes for each post and created_time of each post
"""
tli = []
ti = []
for i in this:
r = graph.get("/"+i['id']+"/likes?limit=200")
li = []
ti.append(i['created_time'])
for j in r['data']: #goes into each posts to get list of likes
li.append(j['name'])
tli.append(len(li))
return tli,ti ## this returns the total no of likes and corresponding created_time
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.