【发布时间】:2014-02-17 11:12:56
【问题描述】:
我正在尝试以下方法:
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('facebook', $this->config->item('fb_config'));
}
public function index() {
$user_id = $this->facebook->getUser();
$data['user_id'] = $user_id;
if ($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$user_profile = $this->facebook->api('/me', 'GET');
echo "Name: " . $user_profile['name'];
} catch (FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $this->facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $this->facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
}
die;
}
}
但我收到此错误:
Invalid or no certificate authority found, using bundled information
OAuthException
Error validating access token: The user has not authorized application XXXXXXXXX.
我能做些什么来解决这个问题?这不是要求用户访问他的个人资料的正确方法吗? 以及如何像在 javascript 中那样添加一些范围
{scope: 'email, user_birthday'}
【问题讨论】:
标签: php facebook codeigniter facebook-php-sdk