Before a minute ago after successful login it redirected to site.com/home, but now the link is site.com/home?state={long-code}6&code={long_code}
And this is ugly. Any ideas?
Update
This is the code i use :
session_start();
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '***',
'secret' => '***',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
'redirect_uri' => 'site.con/home'
)
);
$logoutUrl = $facebook->getLogoutUrl();
//session_destroy();
// Show user data
print_r($user_profile);
Update the sdk files you are using.this error comes from this file base_facebook.php this is now rectified in the new file.
Use this link for getting the latest SDK link
Related
I am creating fb login with the php ,
the problem is that the email of user is not returning from facebook,
FBID and USER NAME is returning.
The same code i have done for another project is working but for the new one is not working
the code is like this
require 'src/facebook.php'; // Include facebook SDK file
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXX', // Facebook App ID
'secret' => 'XXXXXXXXXXXXXXXXX', // Facebook App Secret
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$fbid = $user_profile['id']; // To Get Facebook ID
$fbuname = $user_profile['username']; // To Get Facebook Username
$fbfullname = $user_profile['name']; // To Get Facebook full name
$femail = $user_profile['email']; // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['USERNAME'] = $fbuname;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
header("location:fblogin.php");
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email', // Permissions to request from the user
));
header("location: " . $loginUrl);
}
$user_profile = $facebook->api('/me?fields=name,email');
It´s called "Declarative Fields", see changelog. Btw, you can´t get the username anymore.
Have been trying for weeks, but my App won't ask for extended permissions, obviously that means that it wont POST to the timeline afterwards either.
require_once('/wp-content/php-sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxx',
'secret' => 'xxxxxxx',
));
$user = $facebook->getUser();
if ($userID) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'www.theaandrdepartment.com/raw',
'message' => 'I just helped an Aussie band make it to
radio play! By voting, you can too.'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
} else { $login_url = $facebook->getLoginUrl(array(
'scope' => 'publish_stream'
));
header("Location: ".$login_url);
}
If anyone could help that would amazing.
I copied most of this code straight from the Facebook example, but to no avail.
I have user login implemented on my website. This was working good until now. When i try to login with Facebook account i always get 0 from GetUser(). I tryed with different web browser, updated PHP SDK to latest version, but still not working. Any clue ?
$facebook = new Facebook(array(
'appId' => 'my APP ID',
'secret' => 'my Secret',
'cookie' => false, // enable optional cookie support
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$likes = $facebook->api("/me/likes/ID HIDDEN");
if (!isset($_SESSION['prijavljen'])) {
$_SESSION['prijavljen'] = True;
}
if (!empty($likes['data'])) $fblike = true; else $fblike = false;
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
//$logoutUrl = $facebook->getLogoutUrl();
$logoutUrl = $facebook->getLogoutUrl(array( 'next' => 'my URL'));
} else {
$params = array('scope' => 'email,user_birthday,user_education_history,user_hometown,user_likes', 'redirect_uri' => curPageURL());
$loginUrl = $facebook->getLoginUrl($params);
}
Was the PHP version on your server recently updated? You can try this fix and see if getUser() function starts working for you again.
with my app's administrator acount on facebook my app work normally, but with other account I get error: Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user.
I had this problem before with other app (publish text on the user's wall), but fixed after i added
$user = $facebook->getUser(); What's wrong here? I have added offline_access permission... Help me, please if you can, Thank you very much.
<?php
require_once('images/Facebook.php');
$facebook = new Facebook(array(
'appId' => '456080124457246',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$user_profile = $facebook->api('/me','GET');
$accessToken = $facebook->getAccessToken();
# Get User ID
$user = $facebook->getUser();
$facebook->setAccessToken($accessToken);
$facebook->api(456080124457246);
if ($user) {
try {
# Photo Caption
$photoCaption = $user_profile['name'] . ' patarimų plaukams sužinojo čia http://goo.gl/otwhf';
# Absolute Path to your image.
$imageUrl = 'http://padekime.wu.lt/plaukai/images/PlaukaiNeuzvedus.jpg'; // Example URL
# Post Data for Photos API
$post_data = array(
'message' => $photoCaption,
'url' => $imageUrl
);
$apiResponse = $facebook->api('/me/photos', 'POST', $post_data);
} catch (FacebookApiException $e) {
error_log($e);
}
} else {
$loginUrl = $facebook->getLoginUrl( array(
'scope' => 'publish_stream,photo_upload'
));
echo("<script>top.location.href = '" . $loginUrl . "';</script>");
}
?>
In this case it's not even getting to your $facebook->getUser() call -- it's throwing an exception as soon as it reaches this line:
$user_profile = $facebook->api('/me','GET');
$facebook->api() is a bit of a tricky thing to work with because it throws an exception immediately if it doesn't know who "/me" is...even if you try to fix it later.
The trick, I think, is to wrap the entire thing in a try...catch block. Like so:
<?php
require_once('images/facebook.php');
$facebook = new Facebook(array(
'appId' => '456080124457246',
'secret' => 'xxxxx',
));
try {
$user_profile = $facebook->api('/me','GET');
# Get User ID
$user = $facebook->getUser();
if ($user) {
try {
# Photo Caption
$photoCaption = $user_profile['name'] . ' patarimų plaukams sužinojo čia http://goo.gl/otwhf';
# Absolute Path to your image.
$imageUrl = 'http://padekime.wu.lt/plaukai/images/PlaukaiNeuzvedus.jpg'; // Example URL
# Post Data for Photos API
$post_data = array(
'message' => $photoCaption,
'url' => $imageUrl
);
$apiResponse = $facebook->api('/me/photos', 'POST', $post_data);
} catch (FacebookApiException $e) {
error_log($e);
}
} else {
$loginUrl = $facebook->getLoginUrl( array(
'scope' => 'publish_stream,photo_upload'
));
echo("<script>top.location.href = '" . $loginUrl . "';</script>");
}
} catch (Exception $e) {
$loginUrl = $facebook->getLoginUrl( array(
'scope' => 'publish_stream,photo_upload'
));
echo("<script>top.location.href = '" . $loginUrl . "';</script>");
}
?>
That'll redirect the user to the login url pretty much immediately, then come back with everything in tow. You don't have to set the accessToken with this setup.
This may actually unnecessarily repeat some functionality, but hopefully it's something to start with.
By the way, for what it's worth the offline_access permission is being phased out.
I stopped using "me" keyword to get the logged in user's profile.
instead of $facebook->api('/me','GET'), I changed to $facebook->api('/the facebook ID of the user','GET');
this reduce the need to do second try catch
If you do
if (!empty($user)) {}
That should help...
I am following this tutoril. Though the user is logged in into facebook, but the session is showing him not logged in(NULL session). Please someone help me out. My code-segment is as follows-
$facebook = new Facebook(
array(
'appId' => $app_config['app_id'],
'secret' => $app_config['app_secret'],
'cookie' => true,)
);
$session = $facebook->getSession();
var_dump($session);
$fbme = null;
if ($session) {
try {
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
I had the same situation, changed to iFrame instead of FBML, it worked.