Rest fb: reactions and aliasing fields

158 views Asked by At

I'm using Restfb and want get general information about posts on a certain page. I'm wondering if there is way to get the summary that include total_count for each reaction ? Something like :

"summary": { "total_count": 51, "total_count_HAHA":23, "total_count_LOVE":28, "viewer_reaction": "NONE" }

I can only retrieve the total_count with the documentation provided. I tried to search for solutions online and the commonly used one (in other APIs) is the usage of Aliasing fields. Unfortunately, I couldn't find any info about aliasing in Restfb. Any idea about how to overcome this challenge? :-)

1

There are 1 answers

1
ggkotsis On

i'm new to Restfb and working on a similar case. I've found this (credit to this guy here)

JsonObject obj= facebookClient.fetchObject(post.getId(),JsonObject.class,
                    Parameter.with("fields",
                            "reactions.type(LOVE).limit(0).summary(total_count).as(reactions_love),"+
                                    "reactions.type(WOW).limit(0).summary(total_count).as(reactions_wow),"+
                                    "reactions.type(HAHA).limit(0).summary(total_count).as(reactions_haha),"+
                                    "reactions.type(LIKE).limit(0).summary(total_count).as(reactions_like),"+
                                    "reactions.type(ANGRY).limit(0).summary(total_count).as(reactions_angry),"+
                                    "reactions.type(SAD).limit(0).summary(total_count).as(reactions_sad)"));

It will return you this response (in this example there were no reactions on the post). Your facebook client should be configured to use v2.6 of the graph API Hope this helps :)

{"reactions_haha":{"summary":{"total_count":0},"data":[]},"reactions_angry":{"summary":{"total_count":0},"data":[]},"reactions_sad":{"summary":{"total_count":0},"data":[]},"reactions_like":{"summary":{"total_count":0},"data":[]},"id":"id_of_post","reactions_love":{"summary":{"total_count":0},"data":[]},"reactions_wow":{"summary":{"total_count":0},"data":[]}}