Wednesday, February 22, 2012

"Facebook shares" retrieve in a back end

Sometimes you need to get Facebook shares number of you pages in back end. I was need it for performance reason, it faster to preload this data from Facebook in to Domino document and then show it.

There are two way to do it:

FQL 


You could find examples and explanation following http://developers.facebook.com/docs/reference/fql/link_stat/.

Within FQL you could get shared statistic divided by "share", "like", "comment" and also sum of them.



Graph API


Look http://developers.facebook.com/docs/reference/api/ for"id" query.


Graph API as well as actual "like button" widget shows "total_count" number.  Some people think this is not completely correct, but Facebook developers suppose it's correct.

Example of  read shares from java under the cut

Graph API returns data in JSON fromat. Douglas Crockford create a good Java API for operation with JSON. I create jar from that source. You could download it from my file storage.

So, Facebook Graph API and JSON example of reading shares number:



Result of work:

{"id":"http:\/\/openntf.org\/Internal\/home.nsf","shares":8}

Shares: 8 


Branch example:


Result:
{"http:\/\/openntf.org\/Internal\/home.nsf":{"id":"http:\/\/openntf.org\/Internal\/home.nsf","shares":8},"http:\/\/translate.google.com\/":{"id":"http:\/\/translate.google.com\/","shares":1010668,"comments":1},"http:\/\/www.google.com\/":{"id":"http:\/\/www.google.com\/","shares":3198837,"comments":251}}

{"shares":3198837,"id":"http://www.google.com/","comments":251}
Shares of http://www.google.com/: 3198837

{"shares":8,"id":"http://openntf.org/Internal/home.nsf"}
Shares of http://openntf.org/Internal/home.nsf: 8

{"shares":1010668,"id":"http://translate.google.com/","comments":1}
Shares of http://translate.google.com/: 1010668

No comments: