I getting this error message suddendly and i don't know why because my fb app ran perfectly. My hosting guy said the he moved my site to another server, but he kept the same configuration.
this is my facebook app code:
include 'config.php';
$user = $facebook->getUser();
echo $user;
$loginUrl = $facebook->getLoginUrl(array (
'scope' => 'publish_actions,public_profile,user_friends',
'redirect_uri' => 'http://attila-naghi.com/fb/mytest/test.php'
));
echo 'Login Here ';
and this is the test.php file:
$user = $facebook->getUser(); // here it crashed for some god know reason
if ($user) {
try{
$user_profile = $facebook->api('/me');
$fbid = $user_profile['id']; // To Get Facebook ID
$fbfullname = $user_profile['name']; // To Get Facebook full name
$femail = $user_profile['email']; // To Get Facebook email ID
//FACEBOOK POST
}catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
........
I created a new facebook application, but still the same. I moved in another folder the but still the same. I'm out of idea why I'm still getting this. Can you give some idea ? thx
Just a shot in the dark, but do you have php CURL installed on your new server? Usually request such as these require some back and forth which usually comes in the form of a CURL request, but there are other ways :)
Related
I try to get my user_likes. I got an access token in the Graph API Explorer for user_likes. When I put hardly my PAGE_ID_WANT_TO_CHECK and my ACCESS_TOKEN_USER_LIKES in the url bar, my datas are good shown in my browser. But, in my code when I make the test if my $likes are empty or not, it still say it's empty.
var_dump($likes) is just empty.
Would like to know why and how to have a full array ?
Here my code.
Thank you.
require_once('fb-sdk/facebook.php');
require_once('config.php');
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if ($user_id) {
try {
$likes = $facebook->api('/me/likes/PAGE_ID_WANT_TO_CHECK?access_token=ACCESS_TOKEN_USER_LIKES');
if( !empty($likes['data']) ){
echo "I LIKE!!!!!!";
}else{
echo "not a fan!";
}
} catch (FacebookApiException $e) {
error_log($e);
}
}
var_dump($likes['data']);
//During the login process
$login_url = $facebook->getLoginUrl(array(
'scope' => 'user_likes'
));
My app uses Facebook PHP SDK 3.2.2 to authenticate users, what I've done so far:
$facebook = new Facebook(array('appId' => APP_ID,'secret' => APP_SECRET));
$fbme = $facebook->getUser();
if ($fbme) {
try {
$user_profile = $facebook->api('/'.$fbme);
catch (FacebookApiException $e) {
error_log($e);
$fbme = null;
}
}else{
$login_url = $facebook->getLoginUrl(array('scope' => 'email,publish_actions', 'redirect_uri' => $baseurl));
echo("<script>top.location.href = '" . $login_url . "';</script>");
die();
}
This code gets included at the top of every page. As you can see, is very basic. Everything works, the user gets authenticated but the sessions lasts very short, lets say, around 1hr. Is it possible to configure the FB session timeout anywhere? Thanks.
I have search over and over again and I can't seem to find an answer. What am I doing wrong?
My error is FacebookApiException [ 0 ]: An active access token must be used to query information about the current user.
EDIT Just to add. This worked once or twice, but never in succession.
require_once('media/fb/facebook.php');
$app_id = '123456';
$app_secret = '123456';
$my_url = 'mysiteurl';
$config = array(
'appId' => $app_id,
'secret' => $app_secret,
'fileUload' => 'false');
$facebook = new Facebook($config);
$user = $facebook->getUser();
if($user) {
try {
$user_profile = $facebook->api('/me','GET');
} catch(FacebookApiException $e) {
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$login_url = $facebook->getLoginUrl(array('redirect_uri' => $my_url));
header("Location:" . $login_url);
$user_profile = $facebook->api('/me','GET');
}
Your help is greatly appreciated.
Does your error come from this line: $user_profile = $facebook->api('/me','GET'); at the bottom?
The header function will re-direct the user to Facebook login page which will cause the browser to refresh. You won't get the user's access token immediately after that. You need to wait until the user is redirected back to your website to get the access token. You need to set $my_url to point to the same page of the codes you wrote here.
I know there are tons of topics
on this question, but every single one that I've seen, seems to have no solution at all!
I'm getting the infamous "Oauth Exception - An active access token must be used to query information about the current user" and I don't know what to do.
My facebook connect was working perfectly fine until yesterday, now, it stopped working all of a sudden today.
Can anyone please help me with this?
I'm using php sdk to connect the user to facebook in a pop-up window, then I make him autorize my app and redirect the window to a php called facebookReturn.php.
In this file, I'm supposed to get the user info, save it on Session, then close the window and refresh the main page behind.
Here are my codes.
index.php:
require_once 'phps/facebook.php';
$config = array();
$config[appId] = 'xxxx';
$config[secret] = 'xxxx';
$config[fileUpload] = false;
$facebook = new Facebook ($config);
$facebookId = $facebook->getUser();
echo "<br>facebook id: $facebookId";
if ($facebookId) {
$userProfile = $facebook->api('/me');
$logoutUrl = $facebook->getLogoutUrl();
}
else {
$params = array ();
$params[scope] = 'publish_stream, user_birthday, email, user_activities';
$params[redirect_uri] = 'http://www.mydomain.com.br/phps/facebookReturn.php';
$params[display] = 'popup';
$loginUrl = $facebook->getLoginUrl($params);
}
facebookReturn.php:
require_once 'facebook.php';
$config = array();
$config[appId] = 'xxxx';
$config[secret] = 'xxxx';
$config[fileUpload] = false;
$facebook = new Facebook ($config);
$user = $facebook->getUser();
$userProfile = $facebook->api('/me');
Thank you in advance.
Remomber: Facebook token expires in 60 days.
require_once($_SERVER['DOCUMENT_ROOT'] . '/facebook-php-sdk/facebook.php');
$facebook = new Facebook(array(
'appId' => FB_MAIN_APP_API_ID,
'secret' => FB_MAIN_APP_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;
}
}
Above is the code I'm using to get the Facebook details for my application. In my localhost this is working fine and it gives my Facebook email, user id. After I upload this in to live server this function is not working and it's not giving my Facebook details. I checked on the Facebook app id and it is the correct one.
I cannot figure out why it's not working in live site since it is working in my localhost. Please help me with this. Thank you.
I think problem is in your app which your are using on server. So try the same app which you are using for your localhost and in login and logout url instead of localhost use $_SERVER['HTTP_HOST'].
Example :
$session->fb_logout = $facebook->getLogoutUrl(array('next' => "http://" . $_SERVER['HTTP_HOST'] . "/path/to/logout"));
First check that what $user_profile = $facebook->api('/me'); showing. Just print_r the variable $user_profile.
Ex :
$user_profile = $facebook->api('/me');
print_r($user_profile);
exit;
if it showing blank then surely it will go in catch block. Then write following in catch block.
print_r($e);
exit;
For geting the user id, user need to grant permission
$user_id = $facebook->getUser();
echo $uid;
if($user_id){
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user_id = null;
}
}else{
$login_url = $facebook->getLoginUrl();
echo("<br>login url=".$login_url);
};
After the user grant permission check the login_url, you may access user id.
Try this
Have you checked you have the correct URL in the configuration of your app in Facebook?
I have this piece of code to my FB apps and work properly, could you try it?
$session = $this->facebook->getUser();
if ($session) {
$logoutUrl = $this->facebook->getLogoutUrl();
try {
$data['uid'] = $this->facebook->getUser();
$me = $this->facebook->api($session);
$data['me'] = $me;
} catch (FacebookApiException $e) {
error_log($e);
}
} else {
$loginUrl = $this->facebook->getLoginUrl(
array(
'scope' => 'publish_stream, user_about_me, email',
'redirect_uri' => 'YOUR URL',
'canvas' => 1,
'fbconnect' => 0,
'display' => 'page',
));
}
if (!$session) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
$this->load->view('MY VIEW', $data);