Facebook登录:如何将JavaScript与PHP SDK相结合? [英] Facebook Login: How to combine JavaScript with PHP SDK?

查看:116
本文介绍了Facebook登录:如何将JavaScript与PHP SDK相结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何组合

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

最终目标是让我们可以使用jQuery登录,不知何故,以下行仍然可以工作>

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

$user = $facebook->getUser();

我目前注意到的是,当我使用JavaScript登录时,它不会将会话设置为PHP,因此,它与基于PHP的SDK不兼容(所以$用户在这种情况下仍然是null)

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)

我不是一个大的粉丝$ code >< a href =$ facebook-> getLoginUrl()>使用Facebook登录< / a> ,
,因为它会导致浏览器加载不同的页面登录),然后重定向到网络应用程序。如果我可以加载弹出框以供用户登录,然后透明地重定向回我的网络应用程序,这是更理想的。所以关于如何实现这个用户体验的任何建议将不胜感激。谢谢!

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!

推荐答案

我只是使用Facebook登录按钮 - https://developers.facebook.com/docs/reference/plugins/login/

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

一旦用户已经使用它登录(如果还没有)并授予访问您的应用程序(站点),则PHP-SDK应该在使用Facebook会话和API时没有任何麻烦。

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.

我刚刚尝试使用新版本的3.0 PHP SDK,它肯定是工作。在开发者博客上找到此文件

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


如果您正在使用JavaScript SDK与PHP SDK进行登录,则需要等待JavaScript SDK升级(4周内)。由于cookie格式发生变化,PHP SDK 3.0.0版本将不会与当前的JavaScript SDK配合使用。

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.

换句话说,使用v2 PHP SDK,直到JS SDK被更新。

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

这篇关于Facebook登录:如何将JavaScript与PHP SDK相结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆