我正在尝试使用 facebook PHP SDK 从 facebook 获取用户数据。(我正在使用 codeigniter 开发网站)。但是当我单击登录 url 链接时,它向我显示了一个错误。它显示
错误
发生错误。请稍后再试。
这是 C:\wamp\www\project\application\models\test\facebook_model.php 的代码
<?php
class Facebook_model extends CI_Model {
public function __construct()
{
parent::__construct();
$config = array(
'appId' => 'API Key',
'secret' => 'Secret Key',
'fileUpload' => true,
);
$this->load->library('facebook/Facebook', $config);
$user = $this->facebook->getUser();
$profile = null;
if($user)
{
try {
// Proceed knowing you have a logged in user who's authenticated.
$profile = $this->facebook->api('/me?fields=id,name,link,email');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$fb_data = array(
'me' => $profile,
'uid' => $user,
'loginUrl' => $this->facebook->getLoginUrl(
array(
'scope' => 'email,user_birthday,publish_stream',
'redirect_uri' => 'http://herle.in/flutter/index.php/test/userRegistration2'
)
),
'logoutUrl' => $this->facebook->getLogoutUrl(),
);
$this->session->set_userdata('fb_data', $fb_data);
}
}
这是 C:\wamp\www\project\application\contorllers\userRegistration2.php 的代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class UserRegistration2 extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('test/Facebook_model');
}
function index() {
$fb_data = $this->session->userdata('fb_data'); // This array contains all the user FB information
if((!$fb_data['uid']) or (!$fb_data['me'])) {
echo "<a href='" .$fb_data['loginUrl']. "'>Login</a>";
}
else {
$data = array(
'fb_data' => $fb_data,
);
print_r($data);
}
}
}
在库/facebook 我有 2 个 facebook PHP SDK 文件。即 Facebook.php 和 base_facebook.php
这是链接http://herle.in/flutter/index.php/test/userRegistration2.html并在单击登录链接后显示错误。