douya7309 2011-05-27 03:44
浏览 115
已采纳

Facebook登录:如何将JavaScript与PHP SDK结合起来?

How do I go about combining examples from both

https://github.com/facebook/php-sdk/blob/master/examples/example.php and https://github.com/facebook/connect-js/blob/master/examples/jquery/login.html

The end goal is so that we can use jQuery to sign in, and somehow the following line would still work

$user = $facebook->getUser();

What I currently notice is that when I sign in with JavaScript, it doesn't set the session with PHP, hence, it is incompatible with PHP based SDK (so $user in this case would still be null)

I am not a big fan of <a href="$facebook->getLoginUrl()">Login with Facebook</a>, because it causes the browser to load a different page (the facebook login) and then redirects back to the web app. It is far more ideal if I can load up a popup box for user to signin, and then transparently redirects back to my web app. So any suggestions on how I can go about implementing this user experience would be greatly appreciated. Thank you!

  • 写回答

5条回答

  • douyong1285 2011-05-27 04:26
    关注

    I just use the Facebook login button - https://developers.facebook.com/docs/reference/plugins/login/

    Once the user has used that to login (if they weren't already) and grant access to your app (site), the PHP-SDK should have no trouble using the Facebook session and APIs.

    Update

    I just tried this with the new version 3.0 PHP SDK and it is definitely not working. Found this on the developer blog

    If you are using the JavaScript SDK for login in conjunction with the PHP SDK, you will want to wait for the JavaScript SDK upgrade (coming in 4 weeks). Version 3.0.0 of the PHP SDK won’t cooperate with the current JavaScript SDK due to the cookie format changing.

    In other words, use the v2 PHP SDK until the JS SDK is updated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作