2013-04-03 20 views

回答

7

更新:流星0.6.0

輕微的修改,您需要使用一個API來幫助你,如nodefacebook圖形API:https://github.com/criso/fbgraph

您將需要打個包。您需要創建一個名爲/packages的目錄,並在該目錄中調用fbgraph

每個軟件包需要一個package.js(放置在fbgraph目錄中)。在你package.js您可以使用類似:

Package.describe({ 
    summary: "Facebook fbgraph npm module", 
}); 

Package.on_use(function (api) { 
    api.add_files('server.js', 'server'); 
}); 

Npm.depends({fbgraph:"0.2.6"}); 

服務器端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; 
     } 
    } 
}); 

然後同時記錄在客戶端上

客戶端JS

Meteor.call("postToFacebook", "Im posting to my wall!", function(err,result) { 
    if(!err) alert("Posted to facebook"); 
}); 

Fbgraph回購:https://developers.facebook.com/docs/reference/api/

異步(等待來自Facebook的回調將數據返回到客戶端之前):https://gist.github.com/possibilities/3443021

+0

我相信關於以後你每天https://github.com/criso/fbgraph

的要求清單圖形API文檔回答了這個問題,Meteor 0.6.0發佈了,允許我們聲明對NPM模塊的依賴(https://github.com/meteor/meteor/blob/devel/History.md#v060)。我很好奇這個例子會是什麼樣子,而不是直接把它安裝到'.meteor' – Samo

+0

我做了幾個更新,展示瞭如何在Meteor 0.6.0+中使用它。 Npm模塊需要在包中聲明。 – Akshat

+0

感謝您的更新!這實際上適合你嗎? 'npm.require('fbgraph')'只是爲我返回'undefined',即使我可以看到'fbgraph'模塊出現在我的項目中,並且沒有拋出異常。 – Samo