I have a facebook canvas application and I am using the latest version of the PHP SDK.
I have a workflow that looks like this. User logs into facebook and clicks on the application from their list of apps.
User lands on a form page -> clicks submit -> user doesn’t see that it goes through the form process page and try’s to post to wall -> header redirect to invitation page.
The flow works because I have built in transparent error handling. However, there is no wall post during this first walk through of the flow. Repeat by clicking on facebook icon to go to user home page, click on the application link in the list of user apps.
User lands on a form page -> clicks submit -> user doesn’t see that it goes through the form process page and try’s to post to wall -> header redirect to invitation page.
This time and every time there after it works.
The error I receive during the first try is that the session access_token is invalid. Every single time afterwards, as long as the user does not logout it will work and I will never get a bad token.
ON THE FORM PROCESS PAGE WHERE THE WALL POST CODE IS:
$user = null;
require "/usr/home/app/www/fb/facebook.php";
//facebook application
$fbconfig['appid' ] = "xxx";
$fbconfig['secret'] = "xxx";
$fbconfig['baseUrl'] = "http://www.app.com/fb";
$fbconfig['appBaseUrl'] = "http://apps.facebook.com/app";
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
));
//session_write_close();
$user = $facebook->getUser();
try {
$publishStream = $facebook->api("/me/feed", 'post', array(
'message' => "mess",
'link' => 'http://apps.facebook.com/app',
'picture' => 'http://images.app.com/img.jpg',
'name' => 'name',
'description'=> 'des'
)
);
} catch (FacebookApiException $e) {
d($e);
}
header("Location: https://www.app.com/fb/invite.php");
This is the exact error truncated to leave out information that is erroneous:
FacebookApiException Object
(
[result:protected] => Array
(
[error] => Array
(
[message] => An active access token must be used to query information about the current user.
[type] => OAuthException
)
)
....
So, after pounding my head against the wall for a week… I figured it out!
I had added a script at the end of the first page to make the scroll reset.
On the next page was the processing, that was not working correct until I reached the next page where the invitation screen was to appear. On that page was the FB.init,
After this page was loaded, every time thereafter the app worked correctly. I was scratching my head and couldn’t figure it out. Until I noticed, “oauth : true” was the ONLY thing going on that was NOT being called on the first page. So, in that dumb script that I needed to make the scroll bar go away I added “:oauth : true”…
Lo’ and behold, it works now. I am very upset that it was this code breaking things but VERY happy that I now have it fixed and understand what the issue was!!!