Last time, I came across to integrate Facebook in Salesforce for a client. The client manages different Facebook Pages for his different countries with some countries sharing the same Facebook Account while other countries have their own Account. Wish was that Salesforce Users can comments/like from Salesforce and be especially reactive when negative posts are written on the company page.
While thinking at a solution on how to integrate that into Salesforce, I discovered also at that time that the Facebook API is very complete (less for the streaming), pretty well documented and quite amazing to use.
Salesforce API Limit
Whoever has already coded on Salesforce is aware of the API limits. So when you start with such a job, you try to reduce to as low as possible the number of calls issued from Salesforce. Luckily, Facebook allow performing kind of SQL Queries (called FQL). It allows also writing a list of Queries into a JSON and finally it allows even to perform list of list of queries with different Facebook Access Tokens! Basically, all in one request is possible. I created for this facebook batch request a Schedule which runs every 10 minutes.
Then I came on the Facebook Streaming API. The problem of it, is that Facebook provides its own Authentication Mechanism so I needed to find trick to make that working with Salesforce because Salesforce does not enjoy non-authenticated call.
According to Facebook:
Set up a public endpoint URL that receives both HTTP GET (for subscription verification) and POST (for actual change data) requests from Facebook. The structure of both of these types of requests is described below.
So you need to create an endpoint on which, Facebook will perform a GET to verify what you have implemented, and a POST on which will be effectively transmitted what you have subscribed to.
Apex Rest seems the only possibility but Apex Rest requires also Authentication, normally. However, if you create a public Site, you add your Apex Rest Class in the Public Access Setting, magic, you can perform Apex Rest call on this URL
http://URL_of_my_site/services/apexrest/my_class_name. However, what your Apex Class is allowed to do is still restricted by the Profile Setting of the Public Site.
Efficiency and restrictions
The facebook streaming API is not really fast. Count around 1 minute between the time when you write a post and the time when you get the message pushed to Salesforce. Moreoever, you will have most likely to perform a new callout from Salesforce in order to retrieve what has been posted because you will get just an Id / Timestamp in the streaming message... Just a few services are also supported by the Streaming API. For example, you can't stream comments to a post. But it's still a nice to have!