Facebook login with codeigniter working in localhost but not working on server(live),? - facebook

please help me, I am in little trouble. I am familiar with codeigniter.
but I struggling with Login in With Facebook button. I included all files like facebook.php and base_facebook. Its working in Localhost but not working on server. please help me to fix this issue. when I click login button it's responding blank. I given my controller coding below. Thanks in advance.
public function check_fb()
{
$this->load->model('users/users_model');
$appId = '************'; //Facebook App ID
$appSecret = '************'; // Facebook App Secret
$homeurl = 'Site URL'; //return to home
$fbPermissions = 'email'; //Required facebook permissions
parse_str($_SERVER['QUERY_STRING'],$_REQUEST);
$this->load->library('Facebook', array("appId"=>"******", "secret"=>"*******"));
$fbuser = $this->facebook->getUser();
// Here it self I did't get any response.
if(!$fbuser){
$fbuser = null;
$loginUrl = $this->facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
//echo $loginUrl; exit;
redirect($loginUrl);
}
else
{
$user_profile = $this->facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
$user = new Users();
//echo "<pre>"; print_r($user_profile); exit;
if(!empty($user_profile)){
if(!empty($user_profile['id']))
{
$check=$this->users_model->check_login_facebook_id($user_profile['id']);
if($check)
{
echo 'already Exist';
}
else
{
$result = $this->users_model->update_login_facebook_id($user_profile['id']);
redirect($this->config->item('base_url').'users/dashboard');
}
}
}
}
}

Above code is working pretty cool..! I made mistake in library folder. I renamed base_facebook.php as Base_facebook.php, its case sensitive. if anyone face like this problem, just check twice your library files name. Facebook.php ,base_facebook.php, Fb_ca_chain_bundle security certificate.

Related

My app has been approved for permissions, but cannot use the approved permissions when logging in

I am making a website with the function of linking to facebook and creating posts on fanpage. I have created facebook app and the permissions have been approved enter image description here. All works fine when I login with the admin account of the app but when I login with another user account there is no dialog asking for permission. This resulted in the app not getting the token with the permissions I needed to post.
Hope you can help me.
This is connect function
public function connect($user)
{
$urlAuth = Socialite::driver('facebook')
->scopes([
'pages_manage_metadata',
'instagram_basic', 'instagram_content_publish',
'pages_manage_posts', 'pages_read_engagement',
'pages_show_list'
])
->with(['state' => $user->id])
->stateless()->redirect()
->getTargetUrl();
return $urlAuth;
}
This is callback function
public function callback()
{
$user = Socialite::driver('facebook')->stateless()->user();
$token = $user->token;
if($token){
$facebook = new FacebookPublisher($token);
$account = $facebook->getAccount()->data ?? [];
$userID = request()->state;
if(count($account) == 1){
$account = $account[0];
$userInit = User::findOrFail($userID);
$this->savePageInfo($token, $userInit, $account);
$url = config("api.client.connect_account_url");
}else{
$this->saveAccessToken($token, $pageToken = "", $userID);
$url = config("api.client.connect_page_url");
}
return redirect($url);
}
return $this->error(trans('Connect fail!'), [], 404);
}
Thank you,

Fatal error: require_once(): Failed opening required ... Novice programmer, appreciate any guidance

I'm a novice in server-side programming so any advice is appreciated.
I have some PHP files uploaded on a virtual server (000webhost.com) and I'm having trouble with locating a file I'm requiring in another PHP file. The register.php is attempting to "require_once" the update_user_info.php
Here's the code for register.php (Which I've taken from a tutorial and adjusted it with my variables):
<?php
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'../update_user_info.php');
$db = new update_user_info();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST ['password']) && isset($_POST['branch']) && isset($_POST['gender'])) {
// receiving the post params
$username = $_POST['username'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$branch = $_POST['branch'];
$gender = $_POST['gender'];
// check if user is already existed with the same email
if ($db->CheckExistingUser($email)) {
// user already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
// create a new user
$user = $db->StoreUserInfo($username, $name, $email, $password, $branch, $gender);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["user"]["username"] = $user["username"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["branch"] = $user["branch"];
$response["user"]["gender"] = $user["gender"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameter (username, name, email or password) is missing!";
echo json_encode($response);
}
?>
And here's a screenshot of the error that's occurring when attempting to visit the link containing the register.php:
Screenshot of the error
What I've tried so far:
1- tried to use require_once __DIR__."/../filename.php"; and lots more of the same, basically tinkering the statement with different language constructs and constants.
2-Read tutorials on the correct way to use require once but their cases is almost always very different. Either they are using WAMP/XAMPP -meaning they have a local path not a virtual one- So no luck there.
3- tried to change .htaccess file, as someone said in a post that it solved his problem.
4- I'm certain that both files are uploaded to the same directory. Yet it says "No such file".
Does anyone have an idea of where the error could be stemming from? Thanks in advance!

Retrieving Facebook friends list

I am not able to get the Facebook friends list using the API. It was working fine earlier but not anymore. Here is the code I have used. Can someone help to validate the code. Thanks in advance.
<?php
require_once('PHPMailerAutoload.php');
require_once('PHPMailerConfig.php');
require_once("facebook/facebook.php");
$config = array();
$config['appId'] = '***************';
$config['secret'] = '*******************************';
$facebook = new Facebook($config);
$uid = $facebook->getUser();
if(!empty($_GET['error'])) {
echo "User cancelled the authentication with facebook";
echo "<script>
window.opener.location.href='merror.php';
window.close();
</script>";
exit;
}
if($uid) {
$url = $uid.'?fields=id,work,friends,email,picture.width(450).height(450)';
$user_profile = $facebook->api($url);
$friends = $facebook->api('/me/friends');
$d = '';
foreach($friends['data']as $val) {
$d .= $val['id'].',';
}
}
?>
Please read the docs before posting a question which has been answered here hundreds of times.
See
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends#read
A user access token with user_friends permission is required to view the current person's friends.
This will only return any friends who have used (via Facebook Login) the app making the request.
If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.

Symfony 2.1 Autologin after facebook login

I'm creating an intranet, therefore all users have account automatically created for them. They then go to a url to create their password. All that works great. I'm now trying to allow them to "attach" their Facebook account to their user account. This is where my troubles have started...
I've successfully gotten the user to authenticate properly after a facebook login with this
method in SecurityController
public function loginCheckFacebookAction()
{
$request = $this->getRequest();
$session = $request->getSession();
$response = new Response();
$sessionUser = $this->getUser();
$facebook = $this->get('facebook');
$fbUser = $facebook->getUser(); // facebook id
if ($fbUser) {
try {
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository("IntranetBundle:User");
$user = $repo->findUserByFBID($fbUser);
if($user){
$targetPath = $session->get("_target_path");
$firewall = "secured_area";
$roles = $user->getRoles();
$rolesArray = array();
foreach($roles as $role):
$rolesArray[] = $role->getRole();
endforeach;
$token = new UsernamePasswordToken($user, $user->getPassword(), $firewall, $rolesArray);
$event = new InteractiveLoginEvent($this->getRequest(), $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
$this->get('security.context')->setToken($token);
/*
If I uncomment out either of the following redirects
the redirect happens but the user is not authenticated properly
If I comment them out I'm just rendering my error template. The user
however, is authenticated properly.
*/
if(isset($targetPath)){
//return $this->redirect($targetPath);
} else {
//return $this->redirect($this->generateUrl("ssla_intranet_homepage"));
}
}
} catch (FacebookApiException $e) {
$user = null;
}
// I just render this template to be able to view debug bar.
//User is authenticated properly.
$pageParameters = $this->getPageParameters();
$pageParameters["page"] = "error";
$pageParameters["error"] = array();
$pageParameters["error"]["message"] = "Something went wrong with authentication";
return $this->render('IntranetBundle:Error:index.html.twig', $pageParameters);
}
Do I need to register a listener for all interactive_login events that then handles all post-login redirection rather than trying to redirect within the same method?
First project using Symfony, and this is killing me. Any thoughts?
By the way, I've looked into the FOSFacebookBundle, but wanted to be able to authenticate with a number of different methods, including doctrine, gmail, facebook, and twitter.

Facebook infinite redirect loop during authentication

I am getting an infinite loop in the URL redirect after a user either logs in or is already logged in. The page redirects to the login page if the user is not logged in as expected , but goes in the loop as soon as he enters the credentials.
Following is the code:
<?php
include_once ('facebook.php');
$api_key = 'xxxxxxxxxxxx';
$secret = 'xxxxxxxxxxxx';
global $facebook;
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$uid = $facebook->require_login($required_permissions = 'email,status_update,offline_access');
$facebook->api_client->users_hasAppPermission("offline_access",$uid);
#echo $uid;
# $facebook->api_client->users_setStatus("hello",$uid);
# echo "<p>Your status has been updated</p>";
?>
Interestingly this code was working before, but suddenly started giving me an infinite loop problem. There have been couple of discussion on facebook forum about this but no indication that is a bug or what is the workaround .
Any help would be highly appreciateed.
Thanks
I added the code to direct to login only if the user is not logged in else do not do that. This worked for me! .. Hope it helps.
$is_tab = isset($_POST['fb_sig_in_profile_tab']);
if( !$is_tab ){
$uid = $facebook->require_login($required_permissions = 'email,status_update ,offline_access');
}
else{
$uid = $facebook->get_profile_user();
}