Last active
August 29, 2015 14:14
-
-
Save azhawkes/eaa638a6d517a07b7dab to your computer and use it in GitHub Desktop.
Crude Express microservice for a Facebook connector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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