Skip to content

Commit

Permalink
Merge pull request #8 from fgnass/master
Browse files Browse the repository at this point in the history
Support for fql.multiquery
  • Loading branch information
ddollar committed Jun 25, 2012
2 parents 2189f07 + 0225382 commit 2b51697
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2b51697

Please sign in to comment.