We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    Does anyone have any pointers, suggestions, etc. on how to get "wall" postings from a Facebook account to show up in MODx (Evo 1.0.3+)?

    I don’t use Facebook much but had a conversation with someone who wanted to be able to pull the latest five (say) postings that they made on their FB Wall into a sidebar on their website. Searching the forums I see the thread on MODx and FB Connect, but I’m not sure what that does for me. And unless I’m doing a poorly structured search, I don’t see much else.

    Has anyone done this and if so could you elaborate?
      • 18913
      • 654 Posts
      Okey-dokey ...

      Based on this work :
      I came up with this snippet :

      $url = 'http://facebook.com/feeds/page.php?format=atom10&id='.$id;
      $maxnumber = $max;
      /* The following line is absolutely necessary to read Facebook feeds. Facebook will not
      recognize PHP as a browser and therefore won't fetch anything. So we define a browser here */
      ini_set('user_agent','Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/20090824 Firefox/3.5.3');
      $feed = simplexml_load_file($url);  //Load feed with simplexml
      $fb_array = array();  //Initialize empty array to store statuses	
      foreach ( $feed->entry as $item ) {
      	if ($maxnumber == 0) {
      	} else {
                     $desc = trim($item->title);
      		if ($desc == '') {
      			$desc = trim(strip_tags($item->content));
                      //Converts UTF-8 into ISO-8859-1 to solve special symbols issues
                     $desc = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $desc);  //needed?
                      //Get status update time
                     $pubdate = strtotime($item->published);
                     $propertime = gmdate('F jS Y, H:i', $pubdate);  //Customize this to your liking
                     //Get link to update
                     $linkback = $item->link['href'];
      	       $pos = strpos($linkback, '://www.facebook.com/');
      	       if ($pos === false) {
                       $linkback = 'http://www.facebook.com' . $linkback;
                     //Store values in array
                     $fb_item = array(
                            'desc' => $desc,
                            'date' => $propertime,
                            'link' => $linkback
                     array_push($fb_array, $fb_item);
      $output = '';
      $output .= '<ul>';
      foreach ($fb_array as $k => $v) {
        $output .= '  <li>';
        $output .= ' <b>' . $v['date'] . '</b>';
        $output .= '' . $v['desc'] . '';
        $output .= '  <a href="' . $v['link'] . '" target="_blank">Link</a>';
        $output .= '  </li>';
      $output .= '</ul>';
      return $output;

      (output has some empty quotes as I was messing around with styling and span tags ...)

      which gets called in a doc template or sidebar chunk like this
      [!fb_feed? &id=`19110642979` &max=`5` !]

      (where the id number is the id of the facebook site you’re interested in - in this case that of MODx)

      The result is a style-able and click-able list of the most recent postings the facebook owner has posted to their Wall (assuming I understand all this correctly). Note that this would only work for a public site.

      FWIW, the wall data - including the most recent comment, comment count etc. - is also available from the facebook api code. But it seemed like overkill and this was was more simple for my needs.

        • 4310
        • 2,310 Posts
        Thanks grin
        Works nicely.
          • 12584
          • 208 Posts
          Used exactly the same code as posted and for me I get this error:
          PHP error debug
            Error: 	simplexml_load_file() [function.simplexml-load-file]: http://facebook.com/feeds/page.php?format=atom10&id=19110642979:1: parser error : Document is empty	 
            Error type/ Nr.: 	Warning - 2	 
            File: 	/home/username/public_html/manager/includes/document.parser.class.inc.php(770) : eval()'d code	 
            Line: 	9

          I am editing this post as I think its my total lack of facebook knowledge that is the problem. The profile I have on facebook does not have any wall posting hence no output as I only set it up to get a key for the like buttons, what my plan was to show latest wall postings but these wont be mine so not sure if this can be done.

            • 4310
            • 2,310 Posts
            I was the same, no wall. I think I just used a friends ID for testing
              • 12808
              • 70 Posts
              Working great!!!

              Thanx Man...
                • 31283
                • 22 Posts
                Very cool, just wanted to say thanks. Using this on a new bank site that I’m building and it works perfectly. cool