What are the steps required to perform common Facebook actions in Meteor, using the accounts-facebook
package? I\'m trying to get a friends list, post on a wall
Update: Slight modifications for meteor 0.6.0
You need to use an API to help you such as the nodefacebook graph api: https://github.com/criso/fbgraph
You would need to make a package. You need to make a directory called /packages
and in that a directory called fbgraph
.
Each package needs a package.js
(placed in the fbgraph directory). In your package.js
you can use something like:
Package.describe({
summary: "Facebook fbgraph npm module",
});
Package.on_use(function (api) {
api.add_files('server.js', 'server');
});
Npm.depends({fbgraph:"0.2.6"});
server side js - server.js
Meteor.methods({
'postToFacebok':function(text) {
var graph = Npm.require('fbgraph');
if(Meteor.user().services.facebook.accessToken) {
graph.setAccessToken(Meteor.user().services.facebook.accessToken);
var future = new Future();
var onComplete = future.resolver();
//Async Meteor (help from : https://gist.github.com/possibilities/3443021
graph.post('/me/feed',{message:text},function(err,result) {
return onComplete(err, result);
}
Future.wait(future);
}else{
return false;
}
}
});
Then while logged in on the client
Client side js
Meteor.call("postToFacebook", "Im posting to my wall!", function(err,result) {
if(!err) alert("Posted to facebook");
});
Fbgraph repo : https://github.com/criso/fbgraph
Graph API docs for list of requests: https://developers.facebook.com/docs/reference/api/
Async (To wait for the callback from facebook before returning data to the client): https://gist.github.com/possibilities/3443021