Facebook class for facebook integration.

Hello guys,

I have write a simple FB class to use all basic facebook integration like facebook login/logout, get facebook friends , post status etc. You need to copy this FB.PHP class file and include in your file and use any method you want. I believe you are familiar with classes and object. If you feel any difficulty then can contact me.

 * PHP Facebook API Integration Class
 * Author: Praveen Tiwari
 * Email: 7867praveen@gmail.com
 * Website: http://www.networkocean.com
 * File: FB.php
 * Version: 1.0
 * Copyright: (c) 2014 - Praveen
 * You are free to use, distribute, and modify this software
 * under the terms of the GNU General Public License. See the
 * included license.txt file.


class FB{
 private $app_id;            //    = "Your App ID/API Key goes here";
 private $app_secret;  ///////    = "Your App secret goes here";
 private $facebookId;  ////    = "Your facebook id goes here";
 private $site_url;

public function __construct($app_id,$app_secret,$siteUrl,$facebookId)


public function getFBObj(){

$facebook = new Facebook(array(
 'appId'        => $this->app_id,
 'secret'    => $this->app_secret,
 return $facebook;


public function getAccessToken($facebook)

return $facebook->getAccessToken();

public function getUserLoggedIn($facebook){

$user = $facebook->getUser();


return $user_profile = $facebook->api('/me');


return false;


}///////////////function will return user info if user is logged in or return false if user is not logged in

public function getLoginUrl($facebook){

$loginUrl = $facebook->getLoginUrl(array(
 'scope'            => 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
 'redirect_uri'    => $this->siteUrl,
 return $loginUrl;


public function getLogoutUrl($facebook){

return $logoutUrl = $facebook->getLogoutUrl();


public function postStatus($facebook, $status){

$statusUpdate = $facebook->api("/".$this->facebookId."/feed", 'post', array('message'=> $status));
 return $statusUpdate;


public function postToFacebook($facebook,$params){

$facebook->api('/'.$this->facebookId.'/feed', 'POST', $params);

public function fetchFacebookFrndList($facebook,$userId,$access_token){
 $fql = "SELECT uid, name, pic_square, online_presence
 FROM user
 WHERE online_presence IN ('active', 'idle')
 AND uid IN (
 SELECT uid2 FROM friend WHERE uid1 = ".$userId."

$fql = "SELECT uid, first_name, last_name , pic_square, online_presence FROM user "
 . "WHERE uid in (SELECT uid2 FROM friend where uid1 = $userId)";
 /*$friends = $facebook->facebook(array(
 'method'       => 'fql.query',
 'access_token' => $access_token,
 'query'        => $fql,

$result = $facebook->api(array(
 'method' => 'fql.query',
 'access_token' => $access_token,
 'query' => $fql,

return $result;





Share This Post

Recent Articles

Leave a Reply


© 2019 Networkocean. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie