0

I am currently updating an older Facebook app to version 4.0 of the Facebook PHP SDK. The app simply posts messages to the user's wall, thus requesting the publish_actions permission from the user. Since the app has not yet been submitted for app review, I am testing with a developer account and one test user account.

When I log in to the test user account and open the app, the app checks whether the publish_actions permission has been granted. In my scenario, this works fine for the test user:

FacebookSession::setDefaultApplication($config['appId'], $config['secret']);

$helper = new FacebookCanvasLoginHelper();
try {
  $session = $helper->getSession();
} catch(FacebookRequestException $ex) {
  // When Facebook returns an error
} catch(\Exception $ex) {
  // When validation fails or other local issues
}

if($session) { //When app installed
    $request_perm = new FacebookRequest($session, 'GET', '/me/permissions');
    $response_perm = $request_perm->execute();
    $graphObjectPermissions = $response_perm->getGraphObject()->asArray();

    $permissions = [];
    foreach ($graphObjectPermissions as $key => $permObject) {
        $permissions[$permObject->permission] = $permObject->status;
    }

if(array_key_exists('publish_actions', $permissions) && $permissions['publish_actions']=='granted'){
    echo "Permission granted!";
}

However, when I log in to the developer account and query the permissions of the test user with GET user_id/permissions, the returned graphObject does not contain the permission publish_actions at all (only email and public profile).

array ( 'email' => 'granted', 'public_profile' => 'granted', )

This is the code for the request, $access_token contains the app access token of my app.

$thisSession = new FacebookSession($access_token);
$request_perm = new FacebookRequest($thisSession, 'GET', '/' . $data['user_id'] . '/permissions');
$response_perm = $request_perm->execute();
$graphObjectPermissions = $response_perm->getGraphObject()->asArray();
$permissions = [];//create permissions array

foreach ($graphObjectPermissions as $key => $permObject) {
    $permissions[$permObject->permission] = $permObject->status;
}
var_export($permissions);

What do I need to change/do in order to check the publish_actions permission from the developer account using GET user_id/permissions?

  • Debug your access token here: https://developers.facebook.com/tools/debug/ If that says you don’t have `publish_actions` permission granted, then you really don’t. – CBroe May 05 '15 at 17:53
  • Also, check what API version your app is using. (You find this on the start tab of app dashboard.) – CBroe May 05 '15 at 17:53
  • Any chance the user's previous grant of that permissions is now ignored because your app isn't approved to ask for those permissions in v2.0 or higher of the API? (v1.0 was deprecated last week) – Igy May 08 '15 at 16:45
  • For some reason, the exact same code is now functioning (I had stopped working on it for two months), publish_actions is granted as expected. I assume it was a bug in facebook which now got fixed?! – phinioli Jul 01 '15 at 14:40

0 Answers0