gpt4 book ai didi

php - facebook getlogin 网址无效

转载 作者:行者123 更新时间:2023-12-02 06:37:55 25 4
gpt4 key购买 nike

我想让用户通过 facebook 登录。我正在使用这段代码:

  <?php

require 'include/facebook.php';
require 'include/fbconfig.php';
require 'include/user.php';

$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'cookie' => true
));

$session = $facebook->getSession();

if (!empty($session)) {
# Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
try {
$uid = $facebook->getUser();
$user = $facebook->api('/me');
} catch (Exception $e) {

}

if (!empty($user)) {
# User info ok? Let's print it (Here we will be adding the login and registering routines)
echo '<pre>';
print_r($user);
echo '</pre><br/>';
$username = $user['name'];
$user = new User();
// check user method insert login information to my database and return the result
$userdata = $user->checkUser($uid, 'facebook', $username);
if(!empty($userdata)){
session_start();
$_SESSION['id'] = $userdata['id'];
$_SESSION['oauth_id'] = $uid;
$_SESSION['username'] = $userdata['username'];
$_SESSION['oauth_provider'] = $userdata['oauth_provider'];
header("Location: test.php");
}
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
} else {
# There's no active session, let's generate one
$params = array(
'scope' => 'email'
);
$login_url = $facebook->getLoginUrl($params);
header("Location: " . $login_url);
}
?>

当我运行这个页面时出现问题,它将我重定向到 facebook 主页(到我的帐户)。

拜托,有什么想法吗??
您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的情况。

最佳答案

您使用的是最新的 PHP SDK 吗?从 here 获取最新的 SDK , 然后重试..

[编辑]

将所有对 getSession() 的引用替换为 getUser()

例子:

$session = $facebook->getSession();

它应该说:

$session = $facebook->getUser();

引用:Upgrade to PHP SDK v3.0.0

关于php - facebook getlogin 网址无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14029403/

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