Why am I getting Error message saying I've logged out even though my app seems to work fine?
I've made a simple app for the purpose of posting to a Facebook Page using PHP scripts from my personal web site.
After much trial and error, it seems to work just fine. I can log in to my app via my web site, post something, and it returns to my web site. So all is good.
The one oddity is that despite everything working, I am getting this error in my logs:
OAuthException: Error validating access token: The session is invalid because the user logged out.
I've Googled the error, and from what I've seen, most people are experiencing time outs or being unexpectedly logged out. Solutions range within terms of how to maintain a logged in session.
However, I think my case is different from other questions I've seen because, despite the error, I seem to remain logged in. I can post to my Page wall as many times as I want.
The error does not seem to be generated every time I post to the wall. It seems to come up one out of every three or four, but it is not consistent, and I have not been able to determine a pattern.
Since everything is working, I could just ignore the error message, but that seems to me to be bad practise. I don't want anything sneaking up to bite me later.
Any help or advice would be much appreciated.
The code that drives the Facebook interaction is integrated with my CMS, so some parts of it are spread around, and/or might be obscure because of the parts I had to customize. However, I believe this function has the meat of the PHP interaction. Please let me know if this is sufficient to help determine the source of the problem:
private function executeFacebookPost()
{
// Facebook posts are limited to 420 characters. Links and pictures
// are separate.
$bodyOption = $this->mention->getOption(Action::$BODY);
if (count($bodyOption) == 0)
{
$fbPost = '';
}
else
{
$fbPost = $bodyOption[1];
}
$linkOption = $this->mention->getOption(Action::$LINK_TO);
if (count($linkOption) == 0)
{
$link = '';
}
else
{
$link = $linkOption[1];
}
// Use require_once() and not require() because you might be doing
// some facebook action elsewhere, and this script will die a sad
// death if it's asked to require more than once.
require_once('+facebook/facebook.php');
// Create our Application instance
$facebook = new Facebook(array(
'appId' => Site::getFacebookAppID(),
'secret' => Site::getFacebookSecret(),
));
$fbUser = $facebook->getUser();
if ($fbUser)
{
try
{
$page_id = Site::getFacebookPage();
$page_info = $facebook->api("/$page_id?fields=access_token");
if (!emp开发者_如何学Goty($page_info['access_token']))
{
$args = array(
'access_token' => $page_info['access_token'],
'message' => $fbPost,
'link' => $link,
//'description' => "aaaaaaaasdfsfsdf",
//'picture' => "http://cdn1.kingdomsofcamelot.com/fb/e2/src/img/fte/army_troop.png",
);
$post_id = $facebook->api("/$page_id/feed", "post", $args);
}
}
catch (FacebookApiException $e)
{
error_log($e, 1, 'ebisudave@gmail.com');
}
}
}
When you get your access_token, request offline_access and then your token won't expire.
it's not possible to give help without accessing code. but i think an application(from cellphone,browser,...) changed current token trying to get updates from your facebook account. test it again with this devices logged out.
精彩评论