Created
May 6, 2014 06:11
-
-
Save aaronthorp/bfcbf0170ff362531802 to your computer and use it in GitHub Desktop.
Meteor.JS Facebook ServerSide
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
function Facebook(accessToken) { | |
this.fb = Meteor.require('fbgraph'); | |
this.accessToken = accessToken; | |
this.fb.setAccessToken(this.accessToken); | |
this.options = { | |
timeout: 3000, | |
pool: {maxSockets: Infinity}, | |
headers: {connection: "keep-alive"} | |
} | |
this.fb.setOptions(this.options); | |
} | |
Facebook.prototype.query = function(query, method) { | |
var self = this; | |
var method = (typeof method === 'undefined') ? 'get' : method; | |
var 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'); | |
} | |
Facebook.prototype.getFriendsData = function() { | |
return this.query('/me/friends'); | |
} | |
Meteor.methods({ | |
getUserData: function() { | |
var fb = new Facebook(Meteor.user().services.facebook.accessToken); | |
var data = fb.getFriendsData(); | |
return data; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment