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.
Related
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 :)
Hi all i developed an application for posting tweet using PHp with twitter api 1.1. But that option is only working for me only. If any one authenticated and try to send tweet using that. It's posting tweet on my wall.
How to make this generalized for anyone.
YOUR_CONSUMER_KEY = 'xxxxxxxxxxxxxx';
YOUR_CONSUMER_SECRET = 'xxxx';
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://xxxx/xxxx/getTwitterData.php');
//print_r($request_token);
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$tmessage = $_POST['message'];
$content = $twitteroauth->post('statuses/update', array('status' => $tmessage));
it's posting tweets on your wall because you're using access token and secret of the app, or you're the authenticated user. You need to log in the user you want to post for, get their access token and secret, then use consumer key, secret, user access token and user access secret to post on their behalf.
It's a bit unclear what you're trying to do, but here's a sample post action with Abraham William's library, which you're using:
require_once('twitteroauth.php');
$key = "***";
$secret = "***";
$token = "***";
$token_secret = "***";
$connection = new TwitterOAuth($key, $secret, $token, $token_secret);
$message = "whatever";
$status = $connection->post($message);
$response= $connection->http_code;
if($response !=200){
echo "ERROR";
}else{
echo "life is good";
}
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'm trying to get the UID of the connected user with Facebook SDK for PHP, but it doesn't work, and all other things work properly; it means that the problem is not in the connection to the application.
I tried this code but it is always returning 0 while I'm connected to Facebook; I even tried with other accounts but no solution.
$uid = $facebook->getUser();
$facebook = facebook_get();
$uid = $facebook->getUser();
echo $uid;
and here's facebook_get()
function facebook_get()
{
include('lib/fbapi/facebook.php');
$config = array();
$config['appId'] = '...';
$config['secret'] = '...';
$facebook = new Facebook($config);
return $facebook;
}
Can you post your authentication code you've coded or you're using?
If you post, we can look into your code and give you the answer to why it's returning 0, it could be your authentication code which is not coded properly or it could be config error.etc.
I am on the verge of going crazy I think!
I am logged into my Personal Facebook account on my work machine and the app I am using works fine but on any other machine logged in as me, the app admin or anyone else the page just seems to keep on constantly refreshing with the state parameter in the url just whirring away and changing between page loads. (I have a laptop sitting on my desk, both using Firefox aswell)
I'm sure it was working on all machines that tested it the other day. Today it started with an error but I can't remember the error code but it was to do with the re-direct url not being owned by the domain but this doesn't seem to crop up now.
I am not the admin of the app either.
Here is the relevant code:
<?
error_reporting(0);
// Facebook PHP SDK
include_once "src/facebook.php";
// app id and seret from the facebook app
$appId = 'xxxxxxxxxxxxxx';
$secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
'cookie' => true,
));
//Facebook Authentication part
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'scope' => 'user_status,publish_stream,user_photos'
)
);
if ($user)
{
try
{
// page id and the feed we want
$user_feed = $facebook->api('PAGENUMBER/feed');
echo "<div id=\"graph\">";
$count = 0;
for ($i=0; $i<25; $i++)
{
// only want statuses - no videos, events, links etc.
if ($user_feed['data'][$i]['type'] == "status")
// just grabbing stuff and echoing it out
// blah blah blah
}
}
catch (FacebookApiException $e)
{
$user = null;
}
// close graph div
echo "</div>";
}
// if the user is not logged in then redirect to login page
if (!$user)
{
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
?>
This was a pain but took out the if ($user) and the try catch and the login redirect and all that seemed to work.