我在Codeigniter 2.1项目中的Facebook连接API中遇到了一个非常奇怪和奇怪的问题。我的网站具有社交登录功能,我在本地主机上测试的所有代码都运行良好。但是当我将项目上传到托管服务器时,Facebook连接库始终返回null对象。
我正在使用facebook-php-sdk 3.2,而这下面是我正在使用的代码。
在配置文件夹中我有一个名为facebook.php的文件,其中包含
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'appId' => 'xxxxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
);
?>
我的库文件夹下有一个名为Fbconnect.php的库。包含代码
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
include (APPPATH . 'libraries/facebook/facebook.php');
class Fbconnect extends Facebook {
/**
* Configured the facebook object
*/enter code here
public $user = null;
public $user_id = null;
public $fb = false;
public $fbSession = false;
public $appkey = 0;
public function __construct() {
$ci = & get_instance();
$ci->config->load('facebook', true);
$config = $ci->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser();
$me = null;
if ($this->user_id) {
try {
$me = $this->api('/me');
$this->user = $me;
} catch (FacebookApiException $e) {
error_log($e);
}
}
}
}
?>
以下是我的控制器代码
public function fb_login()
{
$this->load->library('fbconnect');
$user_data = array(
'redirect_uri' => actionLink("signup", 'social', 'Facebook'),
'scope' => 'email'
);
redirect($this->fbconnect->getLoginUrl($user_data));
}
我已经创建了一个名为actionLink的辅助函数,这是它的代码
function actionLink($controller = '', $action = '', $param = '')
{
$url = base_url();
if (strlen($controller) > 0) {
$url .= "$controller";
if (strlen($action) > 0) {
$url .= "/$action";
if (strlen($param) > 0) {
$url .= "/$param";
}
}
}
return $url;
}
请帮助。
答案 0 :(得分:0)
在 Signup.php 中替换第n行。 37至46具有以下内容://inside function social($userType = 'Web')
的 1 即可。尝试解决方案1只是为了确保它的工作,但它不是一般的,它是特定于Facebook
的 2 即可。解决方案No.2与您所做的相同,但在CI的方式:)
$this->load->library('fbconnect');
$socialId = $this->fbconnect->getSocialId();
$this->data['social_id'] = $socialId;
$email = $this->fbconnect->getEmail();
$this->data['email'] = $email;
$name = $this->fbconnect->getName();
$this->data['name'] = $name;
$this->data['url'] = $userType;
<小时/> 解决方案2 :
$className = $userType . "SocialService";
$this->load->library($className);
$socialId = $this->$className->getSocialId();
$this->data['social_id'] = $socialId;
$email = $this->$className->getEmail();
$this->data['email'] = $email;
$name = $this->$className->getName();
$this->data['name'] = $name;
$this->data['url'] = $userType;
实际上你的主要问题是 FacebookSocialService.php 。 您试图以不正确的方式在公共方法中调用私有方法。这就是你无法获取任何细节的原因。解决方案如下:
在您的公共方法中
public function getSomeData()
{
$fbSocialService = new FacebookSocialService();
$some_fb_data = $fbSocialService->getFacebook()->user['some_fb_data'];
return $some_fb_data;
}