Library for integration of Facebook PHP SDK v4 with CodeIgniter 3
Version: 2.0.0
- PHP 5.4+
- CodeIgniter 3
- CodeIgniter session library
- Facebook PHP SDK v4
- Composer
Facebook Canvas support is experimental as I have not been able to test or confirm it working. If you test it, please report back if you had success or failure.
This library do not include or support all available Facebook Graph methods. Any contribution is welcome to add more. But, please read the contributing rules before submitting any pull requests.
- Download the library files and add the files to your CodeIgniter installation. Only the library, config and composer.json files are required.
- In CodeIgniter
/application/config/config.php
set$config['composer_autoload']
toTRUE
. - In CodeIgniter
/application/config/config.php
, configure theSession Variables
. - Update the
facebook.php
config file in/application/config/facebook.php
with you Facebook App details. - Install the Facebook PHP SDK by navigating to your applications folder and execute
composer install
. - Autoload the library in
autoload.php
or load it in needed controllers with$this->load->library('facebook');
. - Enjoy!
The library download includes a sample controller and views. The example code might not be the best or most beautiful code, but it is there to help you get started quicker.
Check if user is logged
$this->facebook->logged_in();
Get login url. This method will only return a URL when using the redirect (web) login method.
$this->facebook->login_url();
Check if user is logged. This method will only return a URL when using the redirect (web) login method.
$this->facebook->logout_url();
Should only be used on the logout redirect url location. This method will unset the Facebook token cookie set by this library only. This method can not be used to log out a user!
$this->facebook->destroy_session();
Check user id.
$this->facebook->user_id();
Check user details.
$this->facebook->user();
Get post from users wall.
Requires user has approved read_stream
permission
/**
* Retrieve a single post from users wall
*
* Required permission: read_stream
*
* @param int $id Post ID
*
* @return array
**/
$this->facebook->get_post($id);
Publish a text to users wall.
Requires user has approved publish_actions
permission
/**
* Publish a post to the users feed
*
* Required permission: publish_actions
*
* @param string $message Message to publish
*
* @return array
**/
$this->facebook->publish_text($message);
Publish a video to users wall.
Requires user has approved publish_actions
permission
/**
* Publish (upload) a video to the users feed
*
* Required permission: publish_actions
*
* @param string $file Path to video file
* @param string $description Video description text
* @param string $title Video title text
*
* @return array
**/
$this->facebook->publish_video($file, $description, $title);
Publish a image to users wall. This method support externally hosted images only.
Requires user has approved publish_actions
permission
/**
* Publish image to users feed
*
* Supports externally hosted images only! No direct upload
* to Facebook.com albums at this time.
*
* Required permission: publish_actions
*
* @param string $image URL to image
* @param string $message Image description text
*
* @return array
**/
$this->facebook->publish_image($image, $message);
Most methods will return an array that include status code and message values so that you can do appropiet actions depending on if, for example, a publishing of a image was successfull or not. A list of more error codes and messages can be found here
Example of returned result for user()
Array
(
[code] => 200
[message] => success
[data] => Array
(
[id] => 3241823947947890785957
[email] => [email protected]
[first_name] => John
[gender] => Male
[last_name] => Doe
[link] => https://www.facebook.com/app_scoped_user_id/3241823947947890785957/
[locale] => en_US
[name] => John Doe
[timezone] => -7
[updated_time] => 2015-04-03T03:22:50+0000
[verified] => 1
)
)