I can create facebook posts with rules, but when I try to delete them I get "(#200) The user hasn't authorized the application to perform this action"
I created a entity reference field on the node and stored the remote id on the facebook publication entity so the correct information are passed to the rule action.
The app is authorized to manage pages.

Comments

oppure created an issue.

achikas’s picture

Same here. I am not sure if this is a module issue.

maybe i need to make some settings in the Facebook app, but have now clue where to start.

Would be great if someone solved this and give a hint how to configure the module or fb app the right way.

LeDoug’s picture

Same here. Look like the remoteDelete() is not working or the wrong token are used.
If anybody has solved this, please give us a hint :D

LeDoug’s picture

I've made it working by updating the facebook php sdk to 4.0 and applying the update patch to the module..... but my client server php version was 5.3 and the new 4.0 SDK require php 5.4....
SO.... after 1-2 hours, I somehow realized that the access token where missing when performing a remote delete.
So I have created my own functions into the fb_autopost module to add the page access token when performing a delete request.

file: fb_autopost\fb_autopost_entity\fb_autopost_entity.rules.inc

I've add in existing function "fb_autopost_entity_rules_action_info"

$actions['delete_from_facebook_MC'] = array(
   'label' => t('Delete from Facebook MC'),
   'group' => t('Facebook Autopost'),
   'parameter' => array(
     'publication_id' => array(
       'type' => 'facebook_publication',
       'label' => t('Target Facebook publication entity'),
       'description' => t('The ID returned from Facebook when creating the publication. Typically stored in the facebook_id property of your FacebookPublicationEntity.'),
     ),
     'destination' => array(
       'type' => 'text',
       'label' => t('Facebook destinations'),
       'options list' => 'available_facebook_destinations',
       'access callback' => 'can_administer_facebook_publications',
       'description' => t('The destination must match the original destination the publication is published on.'),
     ),
   ),
   'base' => 'rules_action_delete_from_facebookMC',
);

After I created a new function named "rules_action_delete_from_facebookMC"

function rules_action_delete_from_facebookMC(FacebookPublicationEntity $publication, $destination) {
  try {
    $fb = facebook_autopost_entity($publication->type);
    if ($destination == 'me') {
        $fb->setRetry(true);
    }
    $fb->setDestination($destination);
    $fb->remoteEntityDeleteMC($publication);
  }
  catch (Exception $e) {
    watchdog_exception('fb_autopost', $e);
    drupal_set_message($e->getMessage(), 'error');
  }
}

file: \fb_autopost\class\FBAutopost.php

I've created a new function named "remoteDeleteMC"

public function remoteDeleteMC($publication_id, $tokens) {
       $this->api('/' . $publication_id, 'DELETE',array('access_token' => $tokens));
       return TRUE;
    }

file: \fb_autopost\fb_autopost_entity\class\FBAutopostEntity.php

I've also created a new function named "remoteEntityDeleteMC" inside the class "class FBAutopostEntity extends FBAutopost"

public function remoteEntityDeleteMC(FacebookPublicationEntity $publication_entity) {
    // Get a wrapper for the entity and extract the remote ID 
    $wrapper = entity_metadata_wrapper('facebook_publication', $publication_entity);
    $remote_id = $wrapper->facebook_id->value();
    // If there is a remote ID in return, then delete the associated
    // publication.
    // GET the publication and associated destination
    $destination = explode('_',$remote_id);
    $destination = $destination[0];
    $pages = mc_fb_autopost_getPagesAccessTokens(variable_get('fb_autopost_account_id', 'me'), variable_get('fb_autopost_token', ''));
    
    // Get a publication Array
    $publication = array(
      'type' => $publication_entity->type,
      'params' => fb_autopost_entity_get_properties($publication_entity),
    );
    $publication['params'] += array('access_token' => $pages[$destination]['access_token']);
    $this->publishParameterPrepare($publication);
    $token = (array_key_exists('access_token', $publication['params'])) ? $publication['params']['access_token'] : '';
    
    // If there is a remote ID and an access token, then delete the 
    // associated publication.
    if (!empty($remote_id) && !empty($token)) {
      return parent::remoteDeleteMC($remote_id, $token);
    }
    else {
      if (empty($remote_id)) {
        throw new FBAutopostException(t('Remote ID could not be found.'), FBAutopost::missing_param, WATCHDOG_ERROR);
      }
      if (empty($token)) {
        throw new FBAutopostException(t('Access token could not be found.'), FBAutopost::missing_param, WATCHDOG_ERROR);
      }
    }
  }

Finaly I've created a new module named "mc_fb_autopost" and add this function to the mc_fb_autopost.module file

function mc_fb_autopost_getPagesAccessTokens($account_id, $account_access_token) {
    $pages = array();
    foreach (variable_get('fb_autopost_pages_access_tokens', array()) as $page_id => $page_access_token) {
        $pages[$page_id] = array(
            'id' => $page_id,
            'access_token' => $page_access_token,
        );
    }
    return $pages;
}

When I 've created my rules to "delete a facebook publication", I 've selected from the "React on event" dropdown list "Delete from Facebook MC" and I has worked like a charm.
I have also a rules which triggers on node update which can now delete and create/recreate a facebook publication so I did not bother to mess with the module edit functionalities.

I hope this help