我想首先生成一个模型来保存这些信息:
rails g model UserData UID:string birthday:string likes:string location:string \n
activities:string books:string movies:string music:string tv:string \n
interests:string post_count:string friend_count:string
然后我收集数据库。
然后我创建文件 $RAILS_ROOT/jobs/update_facebook.rb:
config = YAML::load(File.open("#{RAILS_ROOT}/config/facebook.yml"));
APP_ID = CONFIG['app_id']
fetching_app = FbGraph::Application.new(config['APP_ID']);
access_token = fetching_app.get_access_token(config['production']['client_secret']);
#Don't know what else to put in here
最佳答案
此表单会有点冗余...您如何知道何时使用点赞数数据库而不是使用 API 获取点赞数?您查询 API 的方式可能比您需要的更多,查询 API 很糟糕,因为它很慢。
我还没有在我的应用程序中实现这种缓存,但我知道这样做的最佳方式是这样的:
您缓存所有 API 响应
您订阅您正在跟踪的对象并实现来自 facebook 实时更新的回调(http://developers.facebook.com/docs/reference/api/realtime/)
有了这个,当对象发生变化时,facebook 将 ping 你的应用程序(以链接中描述的某种方式)
当 facebook 通知对象更改时,您会删除 API 调用的缓存,因此您的应用只会在发生更改时请求 API
这就是我所理解的过程......我确信实现 facebook 实时功能将使任何应用程序更快一些
关于ruby-on-rails - 我应该如何将 Facebook 调用数据缓存到我的数据库中,以便 Rails 可以在本地使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7075991/