2013-10-25 41 views
1

我有一個Facebook邀請對話框邀請朋友來我的應用程序,當然我得到一個響應與邀請的用戶ID然後我存儲在一個集合所謂的「組」下的用戶文檔:所以它看起來是這樣的:如何在發佈(服務器端)獲取用戶的Facebook ID流星

{ "creator" : "qzD5X33Jejq5BYRdZ", "name" : "Soccer", "emailAt" : 4, "date" : "10/31/2013", "friends" : [ "dude dude", "another dude" ], "location" : "xxx", "rules" : "Soccer", "desc" : "Soccer", "users" : [ "100006794617787", "100006832923859" ], "_id" : "ZMgzuy88EiSWF6xnS" } 

,並在我的發佈功能,我想只有創建者和用戶有這個組中,我知道訪問用戶採集,我需要使用this.user和客戶端上我使用Meteor.user() 所以我想這:

Meteor.publish("Teams",function(){ 
    return Groups.find({creator:this.userId},{users:this.user.services.facebook.id},{fields:{ 
     date:false, 
     desc:false, 
     rules:false, 
     friends:false, 
     location:false, 
     emailAt:false 
    }}); 
}); 

但是,正如你可以猜到這不工作,任何建議如何使其工作? 注意:即時消息只使用Facebook登錄,所以這是非常方便的使用Facebook的ID。

回答

1

我不確定您可以致電this.user(我認爲)。您需要解決它所以不是this.user使用user並解決它:

var user = Meteor.users.findOne({_id: this.userId}); 

,另一個是小錯字:):

return Groups.find({creator:this.userId, users:user.services.facebook.id}... 

,而不是

return Groups.find({creator:this.userId}, {users:this.user.services.facebook.id}... 
+0

嘗試它,不工作,我認爲我不能調用服務....在發佈功能,這是可能的嗎? –

+0

是的我得到一個錯誤:「無法讀取未定義的屬性'服務' I2048-22:50:04.807(3)?在Meteor.publish.Groups.find.creator [as _handler](app/server/publishes/main .js:16:57)「 –

+0

您是否也將'this.user'更改爲'user'如上所示,它需要解析爲有效的用戶? 'services'屬性應該在服務器上的任何地方可用 – Akshat

相關問題