function Facebook(accessToken) {
FBGraph.setAccessToken(accessToken);
FBGraph.setOptions({
headers: {connection: 'keep-alive'},
pool: {maxSockets: Infinity},
timeout: 3000
});
}
Facebook.prototype.query = function(query, method) {
var self = this,
method = (method==='post') ? 'post' : 'get',
data = Meteor.sync(function(done) {
self.fb[method](query, function(err, res) {
done(null, res);
});
});
return data.result;
}
Facebook.prototype.getUserData = function() {
return this.query('me');
}
Meteor.methods({
getUserData: function() {
var fb = new Facebook(Meteor.user().services.facebook.accessToken);
return fb.getUserData();
}
});
Template.home.events({
'click #btn-user-data': function(e) {
Meteor.call('getUserData', function(err, data) {
$('#result').text(JSON.stringify(data, null, 2));
});
}
});