Creating a Facebook session for getting page info
- by Marty Haught
I am trying to get info on a page that my user is admin for. This user has granted my fb_connect app offline access. I have saved the session_key that allows offline access (it has the user's id in it). I am able to publish to this fan page with this session key. But when I try to access the page's info I get an SessionExpired error. This doesn't make sense. Look at the code and output below:
p is is a 'profile' object that holds the three pieces of relevant fb data (user_id, session_key and page id)
fb_session = Facebooker::Session.create
= #
fb_session.secure_with!(p.fb_session_key, p.fb_user_id, 0)
= nil
fb_session.user.has_permission?("offline_access")
= true
fb_session.user.has_permission?("publish_stream")
= true
fb_session.user.has_permission?("read_stream")
= true
pages = fb_session.fql_query("select fan_count from page where page_id = #{p.fb_page_id}")
Facebooker::Session::SessionExpired: Session key invalid or no longer valid
...
pages = fb_session.pages(:fields = {:page_ids = p.fb_page_id})
Facebooker::Session::SessionExpired: Session key invalid or no longer valid
...
pages = Facebooker::Session.create.fql_query("select fan_count from page where page_id = #{p.fb_page_id}")
= [#]
Perhaps I'm not creating the session right or maybe offline access doesn't give me access to the user's page even though I have permissions to push to it. As you can see when I just use an anon session I'm able to get the fan count, which I'm guessing is publicly available. Does anyone have an idea on this?