Reputation: 11782
I have created a simple canvas app. I have set my access Token in the facebook but this access token is set with scope public_profile, basic_info, user_friends
I also want to add public_action so i can test posting too.
I am using php FacebookSdk 4.0 with following code
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('{app_id}','{app_secret}');
$helper = new FacebookCanvasLoginHelper();
try {
$session = $helper->getSession();
} catch (\Exception $ex) {
echo $ex->getMessage();
}
if($session)
{
$request = new FacebookRequest( $session, 'GET', '/me' );
try{
$response = $request->execute();
$graphObject = $response->getGraphObject();
//echo print_r( $graphObject, 1 );
} catch(FacebookRequestException $ex) {
echo $ex->getMessage();
} catch (\Exception $ex) {
echo $ex->getMessage();
}
try{
$response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'www.example.com',
'message' => 'User provided message'
)
))->execute()->getGraphObject();
} catch(FacebookPermissionException $ex) {
echo $ex->getMessage();
} catch (\Exception $ex) {
echo $ex->getMessage();
}
}
else
{
// show login url
}
With error
(#200) The user hasn't authorized the application to perform this action
How can I give myself publish permissions?
I have managed to get publish permissions using following code
$url = 'https://www.facebook.com/dialog/oauth?client_id=xxx
&redirect_uri=https://xxxx/v1/&scope=publish_actions';
Following is my code from Fb developer docs
try {
$response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'www.example.com',
'message' => 'User provided message'
)
))->execute()->getGraphObject();
echo "Posted with id: " . $response->getProperty('id');
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
I am getting error
Exception occured, code: 100 with message: Invalid parameter
Upvotes: 0
Views: 1431
Reputation: 31479
You can apparantly add the list of requested permissions in the getLoginUrl()
$loginUrl = $helper->getLoginUrl(["public_profile", "publish_actions", ...]);
See
Be aware that with v2.0, you need to have your permissions reviewed before you can request them with your app: https://developers.facebook.com/docs/apps/changelog#v2_0_permissions
Upvotes: 2