Hi all,

I made 2 rules to publish facebook publication of type "PHOTO".

Rule A, check if the facebook_publication_reference is EMPTY, then run "Publish to Facebook page"
Rule B, check if the facebook_publication_reference is NOT EMPTY, then run "Update In Facebook"

-Rule A run perfectly fine.

-Rule B will generate
Insufficient permissions to publish on page with id 0. Please check your configuration.
and when I check my facebook Page, a PHOTO post has been removed

So, I remove the "Update In facebook" action in Rule B and replace it with "Delete from Facebook" then follow by "Publish to Facebook page" to temporarily do what I guess is the same..

So is this a bug or something?

Here I attach my exported current rule, kindly help if anyone notice my rule doesnt fit "Update In facebook".

{ "rules_edit_product_on_facebook_page_if_fbpublication_exist" : {
    "LABEL" : "Edit product on facebook page if fbpublication exist",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "commerce product", "facebook" ],
    "REQUIRES" : [ "rules", "fb_autopost_entity" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_is_of_bundle" : {
          "entity" : [ "node" ],
          "type" : "node",
          "bundle" : { "value" : { "furniture" : "furniture", "mattress" : "mattress" } }
        }
      },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_product" } },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_facebook_publication" } },
      { "NOT data_is_empty" : { "data" : [ "node:field-facebook-publication" ] } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "facebook_publication",
            "id" : [ "node:field-facebook-publication:fbpid" ]
          },
          "PROVIDE" : { "entity_fetched" : { "facebook_publication_fetched" : "Fetched facebook publication" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "facebook_publication",
            "param_type" : "photo",
            "param_user" : [ "site:current-user" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created" ],
          "value" : [ "facebook-publication-fetched" ]
        }
      },
      { "drupal_message" : { "message" : [ "entity-created:fbpid" ] } },
      { "component_rules_get_product_info" : {
          "USING" : { "commerce_product" : [ "node:field-product:0" ] },
          "PROVIDE" : { "image" : { "image" : "image" }, "price" : { "price" : "price" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-facebook-source:file" ],
          "value" : [ "image" ]
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-facebook-message" ],
          "value" : "[node:title]\r\n@-------------------------------------------------@\r\nNow selling for [site:commerce-currency] [price:value] only!\r\n\r\n[node:summary]... \r\nVisit [node:url] for more info!"
        }
      },
      { "delete_from_facebook" : { "publication_id" : [ "facebook-publication-fetched" ] } },
      { "publish_to_facebook" : {
          "USING" : { "publication" : [ "entity-created" ], "pages" : "228074727253202" },
          "PROVIDE" : { "facebook_publication_id" : { "facebook_publication_id" : "Facebook publication returned ID" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:facebook-id" ],
          "value" : [ "facebook-publication-id" ]
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } },
      { "data_set" : {
          "data" : [ "node:field-facebook-publication" ],
          "value" : [ "entity-created" ]
        }
      },
      { "entity_save" : { "data" : [ "node" ], "immediate" : 1 } }
    ]
  }
}

Thanks & best regards,
Max.

Comments

marcus178’s picture

I have a very similar problem. I have 2 rules, after saving new content publish to facebook, and after updating content update on facebook. With the later enable I get the same error when creating new content.

e0ipso’s picture

id 0 means that the page to publish to has not been correctly selected.

e0ipso’s picture

dinotav’s picture

I dont have any rules, only my post_node.module

<?php

function post_node_node_insert($node) {
  if ($node->type == 'article')
  {
    try {
      $fb = new FBAutopost();
      $fb->publish(array(
        'type' => 'link',
        'params' => array(
          'link' => url('node/' . $node->nid, array('absolute' => TRUE)),
          'message' => t('Título mensaje: !title', array('!title' => $node->title)),),));
    } catch (ErrorException $e) {
      drupal_set_message ($e->getMessage(), 'error');
    }
  }
}
?>
e0ipso’s picture

@dinotav, please see the updated instructions.

FAAREIA’s picture

Status: Active » Closed (fixed)

Thanks for the updated instructions.

Just for the record:
- Instructions miss $facebook_page_id.
- Added node url alias and some untested language detection to create full node url alias.

  if ($node->type == 'novedades' || $node->type == 'promociones') {
    global $base_url;
    $site_url = $base_url . base_path();
    $site_language = language_default('language');

    $node_language = $node->language;
    $node_url_unalias = 'node/' . $node->nid;
    $node_url_alias = drupal_lookup_path('alias', $node_url_unalias, $node_language) . '/';
    ($node_language == $site_language ? $node_language = NULL : $node_language .= '/');

    $nodo_url = $site_url . $node_language . $node_url_alias;

    $facebook_page_id = '218519311641980';

    try {
      $fb = new FBAutopost();
      $fb
      ->setDestination($facebook_page_id)
      ->publish(array(
        'type' => 'link',
        'params' => array(
          'link' => $nodo_url,
          'message' => t('!title', array('!title' => $node->title)),
          ),
        ));
    }
    catch (ErrorException $e) {
      drupal_set_message($e->getMessage(), 'error');
    }
  }

Hope it helps some one
PD: I didn't use url() because i don't know how to pass language variable, plus i read about an issue with prefix and domain values in mutilingual sites. url() finally calls drupal_lookup_path

itshaseebanwar’s picture

Learn how to fix issue "Insufficient permissions to publish on page with id" by visiting the below link:

http://www.thesstech.com/drupal-how-fix-Insufficient-permissions-publish...

steveoriol’s picture

Hello, I found why the "0" come in. It is cause by the use of the "array_merge" php function in the function "available_facebook_destinations" inside the file "fb_autopost_entity.rules.inc".
You just have to replace it by a "+" and it works ;-)

Here is the patch:

e0ipso’s picture

@steveoriol that is great. Let's see if someone can RTBC it soon and we can then merge it.