gpt4 book ai didi

php - 检查 Facebook 登录状态 : Client side vs Server side

转载 作者:搜寻专家 更新时间:2023-10-31 21:17:24 25 4
gpt4 key购买 nike

在我正在构建的网站中,我需要检查用户是否登录到 facebook。我有两种可能性。我可以在服务器端执行此操作,使用如下 PHP 代码:

$facebook = new Facebook(array(
'appId' => _FACEBOOK_APP_ID,
'secret' => _FACEBOOK_SECRET,
'cookie' => true));
$me = $facebook->api("/me");
if (isset($me["id"]) {
// User is logged in.
} else {
// User is not logged in.
}

或者,我可以在客户端执行此操作,使用如下 javascript:

FB.getSession();
if (session != null) {
// User is logged in.
} else {
// User is not logged in
}

我想知道这两种方法的优缺点。

最佳答案

我只想指出,您展示的 JavaScript 替代方案已被弃用并且不再有效,文档链接 (http://developers.facebook.com/docs/reference/javascript/FB.getSession/) 重定向到用于处理 OAuth2 的新 getAuthSession() 函数

As of December 13th, 2011, the JavaScript SDK now only supports OAuth 2.0 for authentication. The ability to enable OAuth 2.0 in the JS SDK was first introduced in July. All apps were given until October 1, 2011 to test and migrate. With this change, please ensure that you are using FB.getAuthResponse to obtain the access token instead of FB.getSession. Read more about the specific changes her

关于php - 检查 Facebook 登录状态 : Client side vs Server side,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5789964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com