Guillaume le Floch
Guillaume le Floch

Reputation: 1083

How to get facebook cookie? (javascript)

I'm using javascript for the facebook login, and for posting action. The problem is, if I login on facebook on the page A, I cannot post on a page B because I lost all the facebook information and I have to re-init and to re-log on facebook for posting on a other... and I would like have a login page, and after the user could navigate on the website and post from any page. Is there a way to fix that by using the cookie? or anything else? I looked for getting back but cookie but I still not find out how...

Thanks

Upvotes: 2

Views: 8859

Answers (1)

hagope
hagope

Reputation: 5531

You'll want to persist the Facebook authentication token somewhere, such as a database. Then, using the javascript API to check if the user is logged in:

window.fbAsyncInit = ->
FB.init(appId: '<%= ENV["FACEBOOK_APP_ID"] %>', cookie: true)

$('#sign_in').click (e) ->
  e.preventDefault()
  FB.login (response) ->
    window.location = '/auth/facebook/callback' if response.authResponse

There are several moving parts to a Facebook web app, including client and server authentication. You should check out this Railscast which very thoroughly describes the process:

http://railscasts.com/episodes/360-facebook-authentication

and you can even pull source code: http://media.railscasts.com/assets/episodes/sources/360-facebook-authentication.zip

Upvotes: 1

Related Questions