I'm using Facebook Autopost and Rules to create Facebook link posts when new content is created and that works great, but for the past week I've not been able to figure out how to update and delete the Facebook posts when the content is updated or deleted.

You can follow my posts here:
http://drupal.org/node/1940784

What I am looking for is the following 3 examples using Facebook Autopost and Rules.

1.) When new content is created, a Facebook Autopost type Link is created in Facebook.

2.) When that same content is updated the corresponding Facebook message is also updated.

3.) When that same content is updated the corresponding Facebook message is also deleted.

I have a $20 bounty for these 3 examples.

Comments

PatchRanger’s picture

Hello,

Here are your examples:
1) When new content is created, a Facebook Autopost type Link is created in Facebook.

{ "rules_fb_autopost_create" : {
    "LABEL" : "fb_autopost_create",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "fb_autopost_entity" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_fb_publication" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "facebook_publication",
            "param_type" : "link",
            "param_user" : [ "node:author" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-facebook-link" ],
          "value" : [ "node:url" ]
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-facebook-message" ],
          "value" : [ "node:body:summary" ]
        }
      },
      { "publish_to_facebook_timeline" : {
          "USING" : {
            "publication" : [ "entity-created" ],
            "privacy" : "EVERYONE",
            "retry" : 1
          },
          "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-fb-publication" ],
          "value" : [ "entity-created" ]
        }
      },
      { "entity_save" : { "data" : [ "node" ], "immediate" : 1 } }
    ]
  }
}

2) When that same content is updated the corresponding Facebook message is also updated.

{ "rules_fb_autopost_update" : {
    "LABEL" : "fb_autopost_update",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "fb_autopost_entity" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_fb_publication" } }
    ],
    "DO" : [
      { "edit_in_facebook" : {
          "USING" : {
            "publication_id" : [ "node:field-fb-publication" ],
            "privacy" : "EVERYONE",
            "retry" : 1,
            "destination" : "me"
          },
          "PROVIDE" : { "facebook_publication_id" : { "facebook_publication_id" : "Facebook publication returned ID" } }
        }
      }
    ]
  }
}

3) When that same content is updated the corresponding Facebook message is also deleted.

{ "rules_fb_autopost_delete" : {
    "LABEL" : "fb_autopost_delete",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "fb_autopost_entity" ],
    "ON" : [ "node_delete" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_fb_publication" } }
    ],
    "DO" : [
      { "delete_from_facebook" : { "publication_id" : [ "node:field-fb-publication" ] } }
    ]
  }
}

How to make these examples working:

  1. Install Entity Reference module.
  2. Create a field called fb_publication (so its name will be field_fb_publication) of type "Entity Reference" pointing to "Facebook publication" entity type in content type you need.
  3. Import rules above via Rules interface.

That's it! Additional info could be found here:

Hope it helps.

Regards,
Dmitry Danilson.