Is this action possible with this module somehow?

Comments

fotuzlab’s picture

Currently facebook rules does not provide this option. But certainly this would be a nice addition.
I'll look into it this weekend.

gopherspidey’s picture

I do not have time to put a patch together, but that is easy to add.

You just need to know the page id. Then replace "me" in the graph URL with the Page ID.

Example https://graph.facebook.com/(page id)/feed

You can also do that with a group id.

fotuzlab’s picture

Thats right. In addition to that, we need page's access token and 'manage_pages' permission.

nclavaud’s picture

This would be a much needed feature indeed.

I managed to do that by adding the manage_pages permission in facebook_rules.module, and creating a new Rules action:

function facebook_rules_post_to_page_wall($message, $page_id) {
  global $user;

  // Check if user is connected to facebook.
  // Check if user has granted permission to post on facebook on his behalf.
  $check_grant = facebook_rules_profile_user_grant($user->uid);
  if (!$check_grant || ($check_grant && $check_grant == '0')) {
    return;
  }

  $access_token = facebook_rules_get_token($user->uid);
  $access_token_page = FALSE;

  // fetching the page access token
  $url = "https://graph.facebook.com/me/accounts";
  // for some reason this post request returns an error "(#100) The parameter name is required"
  //$data = facebook_rules_post($url, array('access_token' => $access_token));
  $return = file_get_contents($url . '?access_token=' . $access_token);
  if ($json = json_decode($return)) {
    foreach ($json->data as $pages) {
      if ($page_id == $pages->id) {
        $access_token_page = $pages->access_token;
        break;
      }
    }
  }

  $url = "https://graph.facebook.com/{$page_id}/feed";

  $data = array(
    'access_token' => $access_token_page,
    'message' => $message,
  );
  facebook_rules($url, $data);
}
fotuzlab’s picture

Been quite busy with some other stuff. Could not look into the issue.

@Nicolas: Thanx for the snippet.
However, I feel integration with fboauth(and/or facebook rules) would be unnecessary here for this feature as we need to generate a single access token for the page. Better to create a standalone module for it.

Starting to code! Would hopefully add a usable module by morning IST.

fotuzlab’s picture

Forgot to update the thread. Here is the module Facebook Page Rules

fotuzlab’s picture

Status: Active » Closed (fixed)