I am creating a web app in codeigniter with facebook login, and while sending I have created a API Key and also a response redirect_uri
.
The problem here is while executing the project in the separate file, it's working fine, but when I was trying to integrate to my project. Facebook is asking for permission to enter to the app that's working fine. But the problem is I'm not getting any response from Facebook to display values and store it in the database.
The code which I was sing in my project is shown below. Codeigniter coding format
application
/----config
/----facebook.php // "contains the appId & secret Key"
/----controller
/----book_your_service.php //"contains the facebook_request & facebook_response"
/----libraries
/----Fbconnect.php //contains the URL send and Response
/----facebook "Library file downloaded from github"
/----facebook.php
/----base-facebook.php
Following code is for libraries --> Fbconnect.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include (APPPATH.'libraries/facebook/facebook.php');
class Fbconnect extends Facebook
{
public $user = NULL;
public $user_id = NULL;
public $fb = false;
public $fbSession = false;
public $appkey = 0;
public function Fbconnect(){
$ci =& get_instance();
$ci->config->load('facebook', TRUE);
$config = $ci->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser();
//print_r($this->user_id);
$me = null;
if($this->user_id){
try{
$me = $this->api('/me');
//echo $me;
$this->user = $me;
}catch(FacebookApiException $e){
error_log($e);
}
}
}
}
the following code used in book_your.php for sending and receiving the response from facebook.
// Facebook Login API Code
public function facebook_request()
{
$this->load->library('fbconnect');
$data = array(
'redirect_uri' => site_url('book_your_service/facebook_response'),
'scope' => 'email'
);
redirect($this->fbconnect->getLoginUrl($data));
}
public function facebook_login()
{
//session_start();
$this->load->library('fbconnect');
if($this->fbconnect->user){
echo"<pre>";
print_r($this->fbconnect->user);
echo"</pre>";
}else{
echo "Could not connect this time";
}
}
The facebook Bundle which I was using in this project is shown below https://github.com/puneetkay/Facebook-PHP-CodeIgniter.git