I have searched a lot for this question and found no particular solution for this question.I have seen many examples and so-called solutions but none of them have worked. On top of that I am doing this watching a video by phpacademy and typing exactly as the video.
Before anyone mark this as a duplicate my only question is
Is this because I am testing this in local machine? Because the only difference between my setting and the video is that the tutorial is hosted live and I am testing this in my local machine.
If this is the case?How can I test PHP facebook SDK in my local machine?
Here is my complete code this is my main controller
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Fbapp extends MX_Controller {
function __construct() {
$this->load->library('fbconnect');
parent::__construct();
}
function index() {
echo "<a href='" . base_url() . "fbapp/gotofb'>Go To Facebook</a>";
}
function gotofb(){
$data = array(
'redirect_uri' => base_url() . "fbapp/redirected",
'scope' => "email,photo_upload"
);
$url = $this->fbconnect->getLoginUrl($data);
redirect($url);
}
function redirected(){
$user_id= $this->fbconnect->getUser();
echo $user_id;
}
}
This is my library file that I have named "fbconnect.php",included sdk files inside libraries and incuded in library and I have created a facebook.php inside config which stores appId and secret which i have loaded as $config.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH . 'libraries/facebook/src/facebook.php');
class Fbconnect extends Facebook{
public $user = null;
function __construct() {
$ci =& get_instance();
$ci->load->config("facebook", true);
$config = $ci->config->item('facebook');
parent::__construct($config);
}
}
Steps: 1.i access my url .I click on the link. 2.it get me to the login page of facebook. I login. 3. it redirects me to the redirect uri and prints 0.
Note:I am developing in codeigniter. Thanks in advance. Any help is super appreciated!!