Facebook infinite redirect loop during authentication - facebook

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();
}

Related

Integration of myBB with website

I want my website and my mybb board to be connected. I Googled and made the integration, and I'm able to get a username id, as long as I specify their ID, but nothing happens when I'm using the function as explained.
What I'm trying to do is verify a connection of one to the forums, via my website, and then show their name.
Here's my code, as well as my attempts to get a username:
PHP Code:
define('IN_MYBB', NULL);
require_once 'forums/global.php';
require_once 'forums/class.MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$user = get_user($uid);
while ($forum_user = mysqli_fetch_array($user))
{
echo $forum_user['username'];
}
You could use:
define('IN_MYBB', NULL);
require_once 'forums/global.php';
if(isset($mybb->user['uid'])){
echo "User Found: ".$mybb->user['usernmae']."($mybb->user['uid'].")";
} else {
echo "No user found";
}
MyBBIntegrator isn't even required. But the above code will check if the user is logged in, and display the username and userid. If not it will display No User Found. Hopefully this helps.

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

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.

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.

Fetching FB user-id returns incorrect value ("1")

I have a very strange problem:
Sometimes (but not every time!) when I try to get the current user facebook ID, I get "1";
for example:
$config = array();
$config["appId"] = API_KEY;
$config["secret"] = SECRET;
$facebook= new Facebook($config);
$user=$facbook->getUser();
echo $user['id'];//returns 1;
Obviously - this it not the real user ID.
When I check if the access token is still good -I see that it is still valid. Also, even if I force the user to login again using:
FB.login(function(response) {
if (response.authResponse) {
top.location.href="<?php echo HOME_URL;?>"
}, {scope: 'publish_stream'});
Still getting the same result.
Any idea what could be the problem?
You should ONLY get an ID back from FB:
$user_id = $facbook->getUser();
echo $user_id;
You would later have to query the API for a user profile (which is what it looks like you are doing):
$user_profile = $facebook->api('/me');
Reference:
http://developers.facebook.com/docs/reference/php/facebook-api/

Getting user info after login for facebook application

I have written a small piece to get the user to login :
<?php
include_once ('facebook.php');
$api_key = 'xxxxxxxxxxxxx';
$secret = 'xxxxxxxxxxxxx';
global $facebook;
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
#Ask user to login if not logged in
$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();
}
I need to retrieve the users info once I have the uid. Unfortunately I cannot find the api calls for it and there is a no IDE for facebook :(. Can anyone point me to the api's or give me here. I want to get users username, city, zipcode.
I coudnt get this to work : facebook.Schema.user user = api.users.getInfo();
I think it is for the new API lib.
Thanks.
P.S: I am not using graph APIs, because I found them to be poorly documented and I got stuck with them for a while so decided to abandon them atleast for now.
You can get it like this:
$user_info = $facebook->api_client->users_getInfo($uid, "name, city, zipcode");
print_r($user_info);
More Info:
http://developers.facebook.com/docs/reference/rest/users.getInfo