How to get Reactions ?

17 views
Skip to first unread message

Samir Issa

unread,
Sep 21, 2017, 2:26:11 PM9/21/17
to RestFB
Hi  ! 


I using restFB 2.0.0-rc3 , i´m trying to get Reactions , but all the time get null , the post has 900 reac.

i tried that , may be wrong ?

            Connection<Reactions> reactionsConnection = facebookClient29.fetchConnection("176934912345768_1531928753513037/reactions", Reactions.class);
                int count=0;                
                for( List<Reactions> reac : reactionsConnection){
                 
                 for (Reactions reaction : reac) {
                      
                  for(ReactionItem reactionItem :reaction.getData()){
                    
                   out.println("Reactoins: " + reactionItem.getName());
                   out.println("Reactoins: " + reactionItem.getType());
                   count++;
                  }
                }
                out.println("Total reactions: " + count);
                     
                }

Norbert Bartels

unread,
Sep 22, 2017, 5:12:42 AM9/22/17
to RestFB

Hi Samir,

you should try:

Connection<Reactions.ReactionItem> reactionsConnection = facebookClient29.fetchConnection("<post-id>/reactions", ReactionItem);
for (List<Reactions.ReactionItem> reactions : reactionsConnection) {
   for (Reactions.ReactionItem reactionItem: reactions) {
       out.println("Reactions name: " + reactionItem.getName());
       out.println("Reactions type: " + reactionItem.getType());
   }
}

Do you need all reactions, or only the count? Then you have other possibilities …

Cheers
Norbert

Samir Issa

unread,
Sep 22, 2017, 5:57:17 PM9/22/17
to RestFB
hi ,

all reactions from each posts !!

Thanks

Norbert Bartels

unread,
Sep 24, 2017, 7:19:04 AM9/24/17
to RestFB
Okay, 

then you need to use the above solution.

Fetching only the count of reactions (even splitted up into the different reaction types) is much easier, but in your case you really have to run through all the loops. 
Reactions are paged, so using the endpoint is necessary. 

You can save some calls, if you check on fetching the posts their reaction count and only fetch the reactions if there are any.

Cheers
Norbert

Samir Issa

unread,
Sep 24, 2017, 11:55:40 AM9/24/17
to RestFB
Ok thanks !!
Reply all
Reply to author
Forward
0 new messages