diff --git a/README.md b/README.md index 2697f4e..01724dc 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,18 @@ app.get('/friends_using_app', function(req, res) { }); }); +// perform multiple fql queries at once +app.get('/multiquery', function(req, res) { + req.facebook.fql({ + likes: 'SELECT user_id, object_id, post_id FROM like WHERE user_id=me()', + albums: 'SELECT object_id, cover_object_id, name FROM album WHERE owner=me()', + }, + function(result) { + var inspect = require('util').inspect; + res.send('Yor likes: ' + inspect(result.likes) + ', your albums: ' + inspect(result.albums) ); + }); +}); + // See the full signed request details app.get('/signed_request', function(req, res) { res.send('Signed Request details: ' + require('util').inspect(req.facebook.signed_request)); diff --git a/index.js b/index.js index c2e07fe..3bb5476 100644 --- a/index.js +++ b/index.js @@ -131,9 +131,30 @@ var FaceplateSession = function(plate, signed_request) { } this.fql = function(query, cb) { - restler.get('https://api.facebook.com/method/fql.query', { query: { access_token: self.token, query:query, format:'json' } }).on('complete', function(data) { - cb(data); - }); + var params = { access_token: self.token, format:'json' }; + var method; + var onComplete; + + if (typeof query == 'string') { + method = 'fql.query'; + params.query = query; + onComplete = cb; + } + else { + method = 'fql.multiquery'; + params.queries = JSON.stringify(query); + onComplete = function(res) { + if (res.error_code) + return cb(res); + + var data = {}; + res.forEach(function(q) { + data[q.name] = q.fql_result_set; + }); + cb(data); + }; + } + restler.get('https://api.facebook.com/method/'+method, { query: params }).on('complete', onComplete); } this.post = function (params, cb) {