我需要在2016年8月4日或之前提取Facebook数据。我使用过
import facebook
user = 'nbcolympics'
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts')
feeds = graph.get_connections(profile['id'], 'feed')
但是我在这里得到了所有的帖子和信息。有没有办法提取特定日期之前的数据,比如2016年8月4日?我正在使用Python进行编程
答案 0 :(得分:0)
根据CBroe的建议,可以在主命令中添加时间戳,以根据特定日期提取数据。
until_date_timestamp = int(datetime.strptime('04/08/2016', '%d/%m/%Y').strftime("%s"))
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts', until = until_date_timestamp)
feeds = graph.get_connections(profile['id'], 'feed', until = until_date_timestamp)
如果我们想要指定一个开始日期,那么它就是
until_date_timestamp = int(datetime.strptime('04/08/2016', '%d/%m/%Y').strftime("%s"))
start_date_timestamp = int(datetime.strptime('01/01/2016', '%d/%m/%Y').strftime("%s"))
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts', since = start_date_timestamp,until = until_date_timestamp)
feeds = graph.get_connections(profile['id'], 'feed', since = start_date_timestamp,until = until_date_timestamp)