[Drupal] How to post comments on Facebook wall from Drupal site programatically

By | 08th Jun 2015 | 1 min read

I have a requirement to post a comment on a Facebook user's timeline from our Drupal website. In submitting a Drupal form, I have to post a comment on Facebook. We need to access Facebook api so we have to download Facebook SDK for PHP. Facebook SDk allows developers to access the Facebook api ie to post the comment on Facebook. Also create an app on Facebook, once you create an app it will generate a Facebook app id and Facebook secret code.


      // Include the php sdk file.
      require_once('php-sdk/facebook.php');
      $config = array(
        'appId' => 'YOUR_APP_ID',
        'secret' => 'YOUR_APP_SECRET',
      );
      $fb_url; // Url to show with the comment.
      $message; // Comment to post on your wall.
      $facebook = new Facebook($config);
      // To post the comment on facebook we have to use feed.
      $ret_obj = $facebook->api('/me/feed', 'POST', array(
          'link' => $fb_url,
          'message' => $message,
        )
      );
   

using the above code you can post comment on Facebook from your site.