views:

52

answers:

1

Hey everybody,

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.

+1  A: 

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)

steve
Well, the book is not up to date -written in 2007- but most of the things it talks about actually work, as I in fact have the application running even with the authentication -probably because I am using Facebooker (http://facebooker.rubyforge.org) and this is the "man in the middle" between me and Facebook, but the sessions stuff doesn't seem to work and I don't know where to take a look at..
noloman
Ah - sorry but anything I've written over the years using facebook doesn't seem to work. I think they keep some dependencies working or just randomly change various api calls. I'd strongly recommender hyper graph and the actual facebook graph api.
steve
instead of facebooker you mean?
noloman
Yes! I forgot to say :) The graph api is the lateste api, therefore hopefully the most likely to remain. It's developer by one of the acquired companies (FriendFeed) so it may be the standard going into the future for the facebook api
steve
Nice! It looks very friendly, although now I need to port my app from Facebooker to Hyper-Graph and I'm not sure about how to do it, as I'm a newbie with Rails. Do you know of any tutorial or app's source code where I can take a look in order to learn dig a little deeper and so to learn?Thanks!
noloman
I just used the help page there on the website. It's very simple really, you just make a request to a facebok 'object' and you will have all the JSON available. I'd say just install it locally and play with it in standard ruby and see how that goes.
steve