我正在尝试以下方法:
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'}
答案 0 :(得分:1)
发现问题出在 $ this-&gt; config-&gt;项目('fb_config')数组中 它应该是这样的:
$config['fb_config'] = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'fileUpload' => false, // optional
'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
);