@author: Ahsan Shabbir
@email: iamahsanshabbir@gmail.com
#Installation
cd application/
composer install.
Composer will download facebook sdk in application/vendor directory.
#update config/facebook.php file.
go to application/config/facebook.php file and update it with your facebook app credentials.
#Change Config file
in config.php set composer autoload config as TRUE
$config['composer_autoload'] = TRUE;
in config/autoload.php add facebook in autload library array.
$autoload['libraries'] = array('facebook');
#Library Details
This library use latest facebook api to communicate. I have written following helper methods
1 - loginUrl()
this helper method will return login url for user to login with facebook.
Usage: $this->facebook->loginUrl();
2 - logged_in()
This Helper method will check if user is logged in or not. Return TRUE or False.
Usage: $this->facebook->logged_in();
3 - setSession()
This helper method is used in login callback. This function is responsible for generating user sessions.
When user visit url generated by loginUrl(), he must be directed to this function.
(controller loads it.. check controllers/Fb.php file for more).
4 - getProfile()
This helper method return currently logged in user. And return array of user's data.
Usage: $this->facebook->getProfile();
5 - getUserId()
Sometimes we only need to get userID for checking/comparing user or stuff like that.. this helper method will save your time
and return user id only.
6 - getFriends()
As name of method, this method get list of friends of the user who are already using this app.
If no friend of user use this app, this method will only return number of his friends.
7 - getPosts()
This helper method require permission 'user_posts'.
Usage: $data = $this->facebook->getPosts();
It will return an array of user posts/timeline.
8 - updateStatus($message)
This helper method will update facebook status of user. But it require 'Publish_actions' permission.
usage:
$msg = "Hello, Im posting this status with my new app";
$this->facebook->updateStatus($message)
9 - uploadImage($message, $imagePath)
A helper method to upload images on user facebook timeline. It also require 'publish actions' permission.
Usage:
$msg= "my new selfie";
$img = "/home/ahsan/pictures/selfie.jpg';
$this->facebook->uploadImage($msg,$img);
10 - uploadVideo($title, $description, $video_source)
By calling this function, given video will be uploaded to user timeline.
Usage:
$title = "New Video";
$desc = "This video is not a simple uploaded video. I used facebook api helper by Ahsan Shabbir here";
$video = "/home/ahsan/videos/my-new-video.mp4";
$this->facebook->uploadVideo($title, $desc, $video);
11 - logoutUrl()
This helper method will return url where user is to be redirected after he logged out of facebook.
Value can be set in config/facebook.php file.
12 - logout()
delete user data and destroy session and redirect to logoutUrl() automatically.
#If you find any issues in the code. Please give me your feedback. Any advice and suggestions will be greatly appreciated ...