How to perform common FB actions using Meteor?

前端 未结 1 1661
死守一世寂寞
死守一世寂寞 2020-12-29 16:39

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

1条回答
  •  别那么骄傲
    2020-12-29 16:59

    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

    0 讨论(0)
提交回复
热议问题