2016-04-29 67 views
6

enter image description here我怎樣才能獲得Facebook的圖形API反應彙總數分別

我怎樣才能獲得Facebook的圖形API反應總結分別統計, 當我嘗試在圖形瀏覽器, 例如:?614689638666135_785960901539007 /場= reactions.summary (true) 我得到總數和viewer_reaction,但還不夠,有人請幫助嗎?

+0

心中已經嘗試這樣做,工作對我來說:http://stackoverflow.com/questions/36906590/getting-facebook-post-all-reactions-count-in-single-graph-api-request –

+0

@ JoaoCabral,我也是,同樣的解決方案 –

回答

16

您需要特別要求每個反應,但是如評論中所述,您可以利用字段別名。

>>> fb_get_url = 'https://graph.facebook.com/v2.6/%s' % result['id'] 
>>> query_pieces ['reactions.type(LIKE).limit(0).summary(true).as(like)','reactions.type(LOVE).limit(0).summary(true).as(love)','reactions.type(WOW).limit(0).summary(true).as(wow)','reactions.type(HAHA).limit(0).summary(true).as(haha)','reactions.type(SAD).limit(0).summary(true).as(sad)','reactions.type(ANGRY).limit(0).summary(true).as(angry)', 'reactions.type(THANKFUL).limit(0).summary(true).as(thankful)'] 
>>> full_query = ",".join(query_pieces) 
>>> r = requests.request("GET", fb_get_url, params={'access_token' : my_creds['access_token'], 'fields' : full_query}) 
>>> print(dumps(r.json(), indent=2)) 
{ 
    "love": { 
    "data": [], 
    "summary": { 
     "total_count": 0, 
     "viewer_reaction": "LIKE" 
    } 
    }, 
    "like": { 
    "data": [], 
    "summary": { 
     "total_count": 1, 
     "viewer_reaction": "LIKE" 
    } 
    }, 
    "wow": { 
    "data": [], 
    "summary": { 
     "total_count": 1, 
     "viewer_reaction": "LIKE" 
    } 
    }, 
    "haha": { 
    "data": [], 
    "summary": { 
     "total_count": 0, 
     "viewer_reaction": "LIKE" 
    } 
    }, 
    "sad": { 
    "data": [], 
    "summary": { 
     "total_count": 0, 
     "viewer_reaction": "LIKE" 
    } 
    }, 
    "thankful": { 
    "data": [], 
    "summary": { 
     "total_count": 0, 
     "viewer_reaction": "LIKE" 
    } 
    }, 
    "id": "10100996730306423_10101331756810623", 
    "angry": { 
    "data": [], 
    "summary": { 
     "total_count": 0, 
     "viewer_reaction": "LIKE" 
    } 
    } 
} 
>>> 
+0

謝謝,它的工作! :) –

+0

真棒 - 非常感謝 - 真的幫助我! –

+1

我可以知道Graph API中記錄了哪些內容? – cherhan