mmangino / facebooker2

A simple facebook connect library for ruby
MIT License
311 stars 93 forks source link

Offline access with facebooker2 on rails 2.3.9 #53

Closed maxiperezunlam closed 12 years ago

maxiperezunlam commented 13 years ago

Hello and excuse me.

I have the next problem:

In development enviroment facebooker 2 works correctly. However in production enviroment throw a error whose message is

"session is expired"

I was searching in google and i read about offline access, infinite access_token, etc.

So i give perms to facebook app. Then when i connect and redirect to callback url I wrote these lines.

def create_facebook_user

If current_facebook_user exist: Search the info about facebook_user and then verify if exist a user in my website with

#facebook_user email or id.
if current_facebook_user
  @facebook_user = current_facebook_user.fetch
  @user          = User.fb_user_id_is(current_facebook_user.id.to_i).first
  @user = User.login_is(current_facebook_user.email).first if @user.nil?
end
#IF the search was succesful and not exist a user in my db.
if !@facebook_user.nil? && @user.blank?
  #create a user
  @user            = User.new :login => @facebook_user.email, :email => @facebook_user.email, :name => @facebook_user.name
  @user.fb_user_id = @facebook_user.id.to_i
  @user.state      = "active"
  @user.access_token = @facebook_user.client.access_token

  #A save bug ignore this line
  @user.save_with_validation(false)

  #save again for the BUG.to ignore duplicate save
  if @user.save(:validate=> false)
    @user.profile     = Profile.create(:real_name => @user.name, :benefactor_id => nil, :benefactor_invites => Setting.find_by_identifier("benefactor_invites").value.to_i)
    self.current_user = @user
    redirect_to :controller => "profiles", :action => "show", :id => @user.id
  else
    render "new"
  end
  #if exist a user in my db but never connect with facebook update his/her fb_id
elsif !@facebook_user.nil? && @user.fb_user_id.nil?
  @user.update_attribute :fb_user_id, current_facebook_user.id
  self.current_user = @user
  redirect_to :controller => "dashboard", :action => "index"
  #if exist a user with fb_id => LOGIN
elsif  !@facebook_user.nil?
  self.current_user = @user
  redirect_to :controller => "dashboard", :action => "index"
else
  render "new"
end

end

Ok. I create a user and save access_token. however i don´t understand which are the next steps.

In production facebooker throw a error when i try login (in popup)

"Sorry, something went wrong.

We're working on getting this fixed as soon as we can."

Thanks in advance.

mmangino commented 13 years ago

Can you ask this on the Facebooker google group? You're more likely to get a response there. Also, are you sure you are configured to use the right key?

maxiperezunlam commented 13 years ago

Thanks for your answer. My config is correct. Now i try connect without offline_access. i only use this perms because throw the next error :

Error validating access token: This may be because the user logged out or may be due to a system error.