Truy cập API Facebook và tôi hơi bối rối về cách tiếp cận đúng. Tôi muốn người dùng bỏ qua đăng ký hoặc tự động đăng ký họ nếu họ đăng nhập bằng Facebook. Vì vậy, nếu họ đăng nhập vào Facebook, tôi thu thập id, email của họ và tạo một bản ghi trong bảng người dùng của tôi.Sử dụng Facebook PHP-SDK 3.x để đăng ký/đăng nhập người dùng với Codeigniter 2.1.0
Nếu id đã tồn tại trong bảng người dùng, họ bỏ qua đăng ký tự động và truy cập trực tiếp vào trang thành viên. Đây là mã của tôi cho đến nay (lấy từ ví dụ về PHP SDK của Facebook). Khi tôi chạy tập lệnh đăng ký, trang hiển thị dưới dạng trống, tôi không được chuyển hướng.
CHỈNH SỬA: dường như không đúng sau yêu cầu, nếu tôi sử dụng đoạn mã sau 'kiểm tra' không bao giờ được in.
EDIT: Tôi đang sử dụng Codeigniter và tập lệnh này là một phần của bộ điều khiển, điều đó có gây ra sự cố với yêu cầu không?
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);
}
Bạn đã thử yêu cầu với đường dẫn hệ thống tệp thay vì đường dẫn URL chưa? – BenOfTheNorth