本文介绍了我如何才能分别获得Facebook Graph API反应摘要计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何分别获取Facebook Graph api反应摘要计数,当我在Graph Explorer中尝试时,例如:614689638666135_785960901539007/?fields=reactions.summary(true)
我得到了总数和viewer_reaction,但还不够,请有人帮忙吗?
How can I get Facebook Graph api reaction summary count separately,When I try in Graph Explorer ,ex: 614689638666135_785960901539007/?fields=reactions.summary(true)
I get total count and viewer_reaction, but not enough, somebody please help this ?
推荐答案
您需要明确要求每个反应,但是,如注释中所述,您可以利用字段别名.
You need to specifically ask for each reaction, however as mentioned in the comments, you can leverage Field aliasing.
>>> 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"
}
}
}
>>>
这篇关于我如何才能分别获得Facebook Graph API反应摘要计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!