Facebook + Drupal - Publishing Posts On Social Pages


As social networks gain more and more ground customers are often confronted with the task of integrating their sites with Facebook, Twitter, Google+, etc. While developing a website recently we were asked to establish the cross-posting of the customer site with a Facebook  public page. The relevant desk-top research having been done (Facebook's API and the existing tools for Drupal integration investigated), we eventually bookmarked a method which we are going describe in this post.

First, to create a public page you will have to  specify which of the users will be granted the admin rights (each public page is to be connected at least to one such user) to later administer the settings and possess the right to allow new users onto the page.

Secondly, you will have to create an application in Facebook to establish connection between it and the customer site. For this, a package of Drupal for Facebook modules will have to be Installed and configured. Though, the latter lacks the public pages posting function, it nevertheless has many useful functions and modules that help fulfill various tasks related to Drupal integration with Facebook.

 * Auto publish facebook.
function internetdevels_autopublish_facebook($params) {
  if ($fb = _fb_api_init()) {
    try {
      $page_info = $fb->api('/' . FB_PAGE_ID . '?fields=access_token');
      $params['access_token'] = $page_info['access_token'];
      $fb->api('/' . FB_PAGE_ID . '/feed', 'POST', $params);
    catch (FacebookApiException $e) {
      drupal_set_message(t('Not published to Facebook'));

Here’s an example of a function that will make posting to Fb possible. It can be done with the help of hook_node_presave(), hook_node_insert() or with any other functions relevant to the current task.

  • Sparams — the script array for uploading and publishing the content; Sparams['description'] — description; Sparams['picture'] — picture; Sparams['name'] — title of the post; Sparams['link'] — link.

  • _fb_api_init() — an fb  module functionto check whether a user is logged in FB or not, as well as creating the object on FACEBOOK.

  • FB_PAGE_ID —  the public page id.

  • Spage_info — with this we get the token so that the author of the post would be a public page, not your facebook account.

Additional information:

7 votes, Rating: 5

Read also


It is common knowledge that Google Analytics (hereinafter GA) is a powerful tool for collecting data about user...


Queue API is a particular functional in Drupal that allows you to line up all labor-intensive operations and further check up their implementation on the site. Unlike Batch API,...


This article is about hot quickly to configure the module Search API and...


Our company often uses the Panels module for creating sites. Although this option adds a considerable amount of HTML structures, it...


You sometimes find yourself trying to handle the tasks that require creating a custom table in the database so as to later interact with this table...

Need a quote? Let's discuss the project

Are you looking for someone to help you with your Drupal Web Development needs? Let’s get in touch and discuss the requirements of your project. We would love to hear from you.

Join the people who have already subscribed!

Want to be aware of important and interesting things happening? We will inform you about new blog posts on Drupal development, design, QA testing and more, as well news about Drupal events.

No charge. Unsubscribe anytime