我正在尝试构建一个集成了一些 Facebook 数据的网络应用程序。(特别是 Facebook 活动)。
我想知道处理同步的最佳做法/建议是什么。
这是我目前的想法:在我的数据库中,我需要:
- 用户:拥有 Facebook ID 和好友列表
- 事件:带有用户列表
在猫鼬语法中,它意味着以下模式:
var UserSchema = new Schema({
id: { type: String, default: '' },
friends: [{type : Schema.ObjectId, ref : 'User'}]
})
mongoose.model(‘User', UserSchema )
var EventSchema = new Schema({
eid: { type: String, default: '' },
users: [{type : Schema.ObjectId, ref : 'User'}]
})
mongoose.model('Event', EventSchema)
现在,我使用 Passport-Facebook 处理身份验证和 Facebook-Node-SDK ( https://github.com/Thuzi/facebook-node-sdk ) 进行图形调用。所以我可以在我的 Passport FacebookStrategy 中设置我的 accessToken:
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL
},
function(accessToken, refreshToken, profile, done) {
FB.setAccessToken(accessToken); //Setting access token
User.findOne({ 'id': profile.id }, function (err, user) {
//handling creation in case of error
//then synchronization of friends
})
]);
用户登录后,我将他重定向到一个 URL,该 URL 首先调用一个静态方法来同步当前用户的 FB 事件,然后将他重定向到以下路由:
app.get('/events', events.index)
但这不符合 RESTful 标准?例如,使用我的方法,我不需要这样的路线:
app.post('/events', events.add)
app.put('/events', events.update)
app.del('/events', events.destroy)
事实上,我不知道如何正确实现这种同步化,而且我对前端解决方案的未来集成感到担忧。
有人可以指出我所缺少的并最终给出一些建议/链接来处理这种情况吗?使用官方 Facebook SDK 在客户端处理事件列表并将所需的 ID 提供给我的 API 是否更好?在这种情况下,如何保护数据?
更新:这是这个问题的扩展Web app integration with facebook ( architecture issues ) 关于答案,我无法用我的特殊情况弄清楚。