查看Facebook API,我对使用正确的方法感到困惑。我希望用户跳过注册,或在用户使用Facebook登录时自动注册。因此,如果他们登录Facebook,我收集他们的ID,电子邮件并在我的用户表中创建一条记录。使用Facebook PHP-SDK 3.x使用Codeigniter 2.1.0注册/登录用户
如果用户表中已经存在一个ID,他们会跳过自动注册并直接进入成员页面。这是我迄今为止的代码(取自Facebook的PHP SDK示例)。当我运行注册脚本时,页面显示为空白,我没有被重定向。
编辑:似乎失败后的要求,如果我使用下面的代码'测试'永远不会被打印。
编辑:我使用Codeigniter,这个脚本是控制器的一部分,会导致需求的问题?
require 'http://localhost/facebook-php-sdk-6c82b3f/src/facebook.php';
echo "test";
-
public function signup()
{
require 'http://localhost/facebook-php-sdk-6c82b3f/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user)
{
try
{
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user)
{
$logoutUrl = $facebook->getLogoutUrl();
}
else
{
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
redirect($loginUrl);
}
print_r($user_profile);
$this->load->model("user_model");
$privileges = 1;
$loginLocation = ip2long($_SERVER['REMOTE_ADDR']);
$active = 1;
$this->user_model->add_user($user_profile->id, $user_profile->name, $user_profile->email, $loginLocation, $privileges, $active);
}
您是否尝试过使用文件系统路径而不是URL路径的require? – BenOfTheNorth 2012-02-26 15:35:35