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条)

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题