Facebook + Drupal - Publishing Posts On Social Pages

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 website development 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 to 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() — a fb  module function to 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:

10 votes, Rating: 4.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 Search API Solr search, and how to display the data from Solr server with the help of the module Views.


Our company often uses the Panels module for creating sites. Although this option adds a considerable amount of HTML structures, it provides us with a flexible, user-friendly, and easy-to-operate...


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 through your own requests. Inherent in such...

Subscribe to our blog updates