查看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