dongyikong6207 2013-01-31 20:19
浏览 44
已采纳

在没有明显重定向的情况下将Facebook登录添加到站点的最佳方式

First, I'd like to say this isn't a general question on the Facebook php/javascript sdk. I've successfully added the "Facebook login button" to a few little test projects.

My question is, what is the best way to show the user is wanting to log in with Facebook. Just because someone is logged in to Facebook when the visit my site, doesn't necessarily mean they want to login to my site with Facebook.

I know that after authorizing the user with a FB app, it redirects with a variety of $_GET variables, but if my user is returning to my site, and has already authorized my app, how can I create a "Facebook Login" button that basically 'says' If user clicks this button, pull Facebook user_profile, and use their info for login, else require Facebook login as normal.

I know I could create a button, forward to a page, set a session var, and redirect to the main page, but I'd like to create this effect without noticeable redirections; no redirections if possible.

  • 写回答

2条回答 默认 最新

  • duanfangfei5558 2013-01-31 20:41
    关注

    I think you want to use FB.getLoginStatus. You'll asynchronously get a response telling you the auth state, and you can manually go from there (show their info, log them in, redirect if you want, etc).

    From the SDK reference (https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/):

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token 
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
      } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
      } else {
        // the user isn't logged in to Facebook.
      }
     });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件