2016-08-12 36 views
0

我需要拉動2016年八月或4日前Facebook的數據我已經使用Facebook數據拉:我如何在python中的特定日期之前拉數據?

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進行編程

+1

https://developers.facebook.com/docs/graph-api/using-graph-api/ #paging – CBroe

+0

@CBroe這很有幫助,但是如何在python命令中指定它。 – prashanth

+0

爲此,您必須檢查您正在使用的任何框架的文檔。 – CBroe

回答

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) 
相關問題