pavelk2 / social-feed

JavaScript plugin that shows a user feed from the most popular social networks
http://pavelk2.github.io/social-feed-example/
MIT License
963 stars 304 forks source link

How to add FB comments and likes, Twitter retweets and favorites counts #270

Open Morphinof opened 6 years ago

Morphinof commented 6 years ago

This is missing from the plugin but can be added very quickly :

For Twitter pretty easy to get those rts and favs, you have to add the following line to unifyPostData function of the twitter section of the code : post.rts_count = element.retweet_count; post.favs_count = element.favorite_count;

an then refers to it in your template as follow : {{? it.social_network=="twitter"}} <i class="fa fa-retweet" aria-hidden="true"></i> {{=it.rts_count}} <i class="fa fa-heart" aria-hidden="true"></i> {{=it.favs_count}} {{?}}

For Facebook it needs a little more since those data are not fetched from the request url. First you have to change the "fields" var in the getData function of the facebook section : var fields = '?fields=id,from,name,message,created_time,story,description,link,comments.limit(1).summary(true),likes.limit(1).summary(true)';

then you can add those new data to the element in unifyPostData (of the facebook section of course) : post.likes_count = element.likes.summary.total_count; post.comments_count = element.comments.summary.total_count;

finally refers them in your template as follow : {{? it.social_network=="facebook"}} <i class="fa fa-comments" aria-hidden="true"></i> {{=it.comments_count}} <i class="fa fa-heart" aria-hidden="true"></i> {{=it.likes_count}} {{?}} And you're done ! Hope it'll help some of you

HartLarsson commented 6 years ago

you can create a pull request, so is more easy to debug and apply :)

Morphinof commented 6 years ago

I'll try this week, if i don't forget ;)

mutiullah7 commented 6 years ago

@Morphinof you tried?

Morphinof commented 6 years ago

No i didn't i was on some Ruby project, no time ^^