使用 Facebooker 和 Ruby on Rails 时出现会话问题

发布于 2024-09-14 08:31:24 字数 1056 浏览 11 评论 0原文

我正在阅读《Facebook 平台开发》一书,以便尝试为 Facebook 编写一个小游戏,我遇到了一个“小”问题:我试图在每次登录时将用户插入到我计算机的数据库中。我正在使用书中编写的几种方法,但似乎存在一些问题:

  1. 我似乎无法使用 RoR 的 Facebooker 帮助程序从 Facebook 检索 session_key,因此该值在 。

  2. 每次重新加载网页时,我都可以看到,即使 facebook_id 相同,同一用户也会添加到数据库表的另一行中,尽管它不应该;如果发生变化,它只是应该更新属性 session_key - 无论如何,现在这是 null。

以下是我为了执行这一切而使用的三种方法:

def self.for(facebook_id,facebook_session=nil)
    user = User.find_or_create_by_facebook_id(facebook_id)
    unless facebook_session.nil?
      user.store_session(facebook_session.session_key)
    end
  end

  def store_session(session_key)
    if self.session_key != session_key
      update_attribute(:session_key, session_key)
    end
  end

  # Re-create a Facebooker::Session object outside a request
  def facebook_session
    @facebook_session ||= returning Facebooker::Session.create do |session|
      # Facebook sessions are good for only one hour storing
      session.secure_with!(session_key,facebook_id,1.hour.from_now)
    end
  end

提前非常感谢大家!1。

I am reading the book Facebook Platform Development in order to try to code a small game for Facebook, and I have come across a "little" problem: I am trying to insert a user every time this is logged, into a database in my computer. I am using a couple of methods written in the book, but there seems to be a couple of problems:

  1. I can't seem to retrieve the session_key from Facebook using the Facebooker helpers for RoR, and thus this value is null into the table in my database.

  2. Every time I reload the webpage, I can see that even though the facebook_id is the same, the same user is added in another row to my table in the database, even though it shouldn't; it's just supposed to update the attribute session_key if this changes -anyway, right now this is null.

These are the three methods I am using in order to perform all this:

def self.for(facebook_id,facebook_session=nil)
    user = User.find_or_create_by_facebook_id(facebook_id)
    unless facebook_session.nil?
      user.store_session(facebook_session.session_key)
    end
  end

  def store_session(session_key)
    if self.session_key != session_key
      update_attribute(:session_key, session_key)
    end
  end

  # Re-create a Facebooker::Session object outside a request
  def facebook_session
    @facebook_session ||= returning Facebooker::Session.create do |session|
      # Facebook sessions are good for only one hour storing
      session.secure_with!(session_key,facebook_id,1.hour.from_now)
    end
  end

Thanks a lot in advance to everybody!1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-09-21 08:31:30

嘿,可悲的是 Facebook 一直在改变它的 API!

确保本书是最新的,并且截至本书编写时 API 均未发生更改。还要检查 gem 是否也是最新的。

我个人在处理 facebook 时使用 http://github.com/chrisdinn/hyper-graph 。它调用 Facebook 图表 (graph.facebook.com)

Hey sadly facebook changes its API all the time!

Make sure that the book is up to date and that none of the API has changed as of when the book was written. Also check that the gem is also up to date.

I personally use http://github.com/chrisdinn/hyper-graph when dealing with facebook. It makes calls to the facebook graph (graph.facebook.com)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文