How to perform common FB actions using Meteor?

风流意气都作罢 提交于 2019-12-18 12:01:36

问题


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, and eventually perform other actions, but I'm unsure how to proceed.


回答1:


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



来源:https://stackoverflow.com/questions/15788459/how-to-perform-common-fb-actions-using-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!