2

我正在使用 javascript 进行 Facebook 登录和发布操作。问题是,如果我在页面 A 上登录 facebook,我无法在页面 B 上发帖,因为我丢失了所有 facebook 信息,我必须重新初始化并重新登录 facebook 才能在其他页面上发帖...我想要一个登录页面,并且在用户可以在网站上导航并从任何页面发布之后。有没有办法通过使用cookie来解决这个问题?还是别的什么?我想找回但饼干,但我仍然不知道如何......

谢谢

4

1 回答 1

1

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

于 2012-06-26T23:24:20.040 回答