Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Crude Express microservice for a Facebook connector
var Express = require('express');
var BodyParser = require('body-parser');
var CredentialsService = require('infusionsoft-credentials');
var app = Express();
app.use(BodyParser.json());
app.get('/activities', function(req, res) {
var accessToken = CredentialsService.resolveCredentials(req.params.credentialsId).accessToken;
var since = req.params.since;
var until = req.params.until;
var feedsToFetch = ['feed', 'links', 'photos', 'posts', 'events', 'milestones'];
var feedsFetched = 0;
var channelEvents = [];
// Iterate through all the Facebook feeds we want to fetch
for (var i = 0; i < feedsToFetch.length; i++) {
var url = 'https://graph.facebook.com/' + pageId + '/' + feedsToFetch[i] + '?since=' + since + '&until=' + until + '&accessToken=' + accessToken;
// Fetch and process data for this feed
getFacebookData(url, function(rawData) {
rawChannelEvents.push(transformRawFacebookDataToChannelEvents(rawData));
feedsFetched++;
// If we're done with all the feeds, send the HTTP response
if (feedsFetched == feedsToFetch.length) {
res.send(channelEvents); // done!
}
});
}
});
app.listen(8080);
function getFacebookData(url, cb) {
// TODO - get data from Facebook and pass it to cb()
}
function transformRawFacebookDataToChannelEvents(rawData) {
// TODO
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment