我有这个代码开始使用带有Codeigniter的Facebook SDK V4。这是Facebook SDK文件夹文件旁边的Library Folder中的Facebook.php文件:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( session_status() == PHP_SESSION_NONE ) {
session_start();
}
define('FACEBOOK_SDK_V4_SRC_DIR', APPPATH . 'libraries/facebook/Facebook');
require_once("autoload.php");
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/Entities/AccessToken.php' );
require_once( 'Facebook/HttpClients/FacebookHttpable.php' );
require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php' );
require_once( 'Facebook/HttpClients/FacebookCurl.php' );
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookHttpable;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookCurl;
class Facebook {
var $ci;
var $helper;
var $session;
var $permissions;
public function __construct() {
$this->ci =& get_instance();
$this->permissions = $this->ci->config->item('permissions', 'facebook');
echo $this->ci->config->item('api_id', 'facebook');
exit;
我遇到了一些错误,发现问题是配置变量没有加载。
我的配置文件是这样的:
<?php
$config['facebook']['api_id'] = 'api-id-key';
$config['facebook']['app_secret'] = 'app-secret-key';
$config['facebook']['redirect_url'] = 'http://neuronr.com/facebook/redirect';
$config['facebook']['permissions'] = array(
'email',
'user_location',
'user_birthday'
);
我在配置文件中做错了什么?我已经阅读了文档,对我来说似乎都是正确的。
感谢您的帮助:)
答案 0 :(得分:0)
现在我的代码工作了。只添加了一行:
$this->ci->load->config('facebook'); // this is the line that I added
感谢您的灵感:)