The php code snippet mentioned below does the following:
1. Log in if the user isn't logged in to facebook
2. Asks if the user wants to add the application and grants the requested permissions (in my case: publish_stream and offline_access) in one dialog
3. returns to the page you specified under redirectUrl with an access_token (and because we requested for offline access this one doesn't expire)
The token is then stored in the database so we don't have to request it again.
Now you can, if you wish use the facebook code, or you're own code to get the users data, or other information from facebook (be sure you requested the right permissions)
<?php
// Config
$this->redirectUrl = 'http://www.mywebsite.com/facebook'
$this->clientId = 'APPLICATION_ID';
$this->permissions = 'publish_stream,offline_access';
// Check if a sessions is present
if(!$_GET['session'])
{
// Authorize application
header('Location: http://www.facebook.com/connect/uiserver.php?app_id='.$this->clientId.'&next='.$this->redirectUrl.'&perms='.$this->permissions.'&return_session=1&session_version=3&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request');
}
else
{
$token = json_decode($_GET['session']);
echo $token->access_token; // This is the access_token you'll need!
// Insert token in the database or whatever you want
}
?>Original Question From Stackoverflow:
I am trying to request permission to publish photos from a facebook fan page tab(iframe).
I am calling Facebook.showPermissionDialog('publish_stream'); before the upload(which doesn't seem to do much)
But I keep on getting this error when I try to upload a photo
**caught exception 'FacebookRestClientException' with message 'Permissions error'**
1 year 17 weeks ago