Facebook Feed Problem

Discussion in 'HOWTO-Related Questions' started by Nadim99, Oct 27, 2007.

  1. Nadim99

    Nadim99 New Member

    I used the tutorial for how to set up a Facebook reader application for your blog and I get the following error on my canvas page:
    Code:
    Warning: Invalid argument supplied for foreach() in /home/tajaddod/public_html/facebook_apps/rss/rss_test/index.php on line 20

    I tried it with a thousand different feeds including the forge one: same error.

    Any one else getting this? Any idea what could be wrong?

    Thanks!
     
    Last edited: Oct 27, 2007
  2. falko

    falko Super Moderator Howtoforge Staff

    Have you downloaded the latest Facebook PHP API? They've modified it a little bit recently...
     
  3. Nadim99

    Nadim99 New Member

    yes, its the latest , I downloaded everything I needed fresh today.
    :(
     
  4. Nadim99

    Nadim99 New Member

    The only part where I might not have done exactly what I was supposed to is this action:
    I created a directory called 'rss' in the same directory where facebook.php and index.php etc. are. In it I placed the 'extlib' folder, 'rss_cache.inc', 'rss_fetch.inc', 'rss_parse.inc', 'rss_utils.inc' and 'snoopy.class.inc'.

    Did I translate it correctly?
     
  5. falko

    falko Super Moderator Howtoforge Staff

    What's in /home/tajaddod/public_html/facebook_apps/rss/rss_test/index.php?
     
  6. Nadim99

    Nadim99 New Member

    index.php

    <?php
    define('MAGPIE_CACHE_DIR', './magpie_cache');
    define('MAGPIE_CACHE_ON', 1);
    define('MAGPIE_CACHE_AGE', 600);

    require_once('appinclude.php');

    require_once('rss/rss_fetch.inc');
    $rss = @fetch_rss('http://www.howtoforge.com/node/feed');

    $fbml = '<div style="margin:0 10px 0 10px;">';
    $fbml .= '<table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$rss->channel['link'].'" style="font-weight: bold;">'.$rss->channel['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
    <meta name="medium" content="blog"/>
    <meta name="title" content="'.htmlspecialchars(strip_tags($rss->channel['title'])).'"/>
    <meta name="description" content="'.htmlspecialchars(strip_tags($rss->channel['description'])).'"/>
    <link rel="target_url" href="'.$rss->channel['link'].'"/>
    </fb:share-button></td></tr></table>';


    foreach ($rss>items as $item) {
    $fbml .= '<div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC; border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
    <meta name="medium" content="blog" />
    <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />
    <meta name="description" content="'.htmlspecialchars(strip_tags($item['description'])).'" />
    <link rel="target_url" href="'.$item['link'].'" />
    </fb:share-button></td></tr></table></div>';
    if($item['description']) $fbml .= $item['description'];
    $fbml .= '</div>';
    }
    $fbml .= '</div>';

    $facebook->api_client->profile_setFBML($fbml, $user);
    echo $fbml;
    ?>
     
  7. Nadim99

    Nadim99 New Member

    Strangely enough when i followed the steps in this tutorial (which is practically the same) it worked. But not with all feeds.

    The mystery remains.
     
  8. falko

    falko Super Moderator Howtoforge Staff

    It must be
    Code:
    foreach ($rss[B][COLOR="Red"]-[/COLOR][/B]>items as $item) {
     
  9. fuller_paul

    fuller_paul New Member

    invalid argument problem

    Hi falko,

    I'm getting the same problem the guy above was ("Invalid argument supplied for foreach"), but my index.php syntax on that line was correct:
    <?php
    define('MAGPIE_CACHE_DIR', './magpie_cache');
    define('MAGPIE_CACHE_ON', 1);
    define('MAGPIE_CACHE_AGE', 600);

    require_once('appinclude.php');

    require_once('rss/rss_fetch.inc');
    $rss = @fetch_rss('http://feeds.feedburner.com/GoingToSeminary');

    $fbml = '<div style="margin:0 10px 0 10px;">';
    $fbml .= '<table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$rss->channel['link'].'"

    style="font-weight: bold;">'.$rss->channel['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
    <meta name="medium" content="blog"/>
    <meta name="title" content="'.htmlspecialchars(strip_tags($rss->channel['title'])).'"/>
    <meta name="description" content="'.htmlspecialchars(strip_tags($rss->channel['description'])).'"/>
    <link rel="target_url" href="'.$rss->channel['link'].'"/>
    </fb:share-button></td></tr></table>';


    foreach ($rss->items as $item) {
    $fbml .= '<div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC;

    border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a

    href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
    <meta name="medium" content="blog" />
    <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />
    <meta name="description" content="'.htmlspecialchars(strip_tags($item['description'])).'" />
    <link rel="target_url" href="'.$item['link'].'" />
    </fb:share-button></td></tr></table></div>';
    if($item['description']) $fbml .= $item['description'];
    $fbml .= '</div>';
    }
    $fbml .= '</div>';

    $facebook->api_client->profile_setFBML($fbml, $user);
    echo $fbml;
    ?>
     
  10. falko

    falko Super Moderator Howtoforge Staff

    Is it possible that $rss is empty? Please check if the fetch_rss function returns anything ($rss = @fetch_rss('http://feeds.feedburner.com/GoingToSeminary');).
     
  11. fuller_paul

    fuller_paul New Member

    Yep, $rss was empty

    Being very new to PHP (1 day), I was trying all sorts of things since I asked my question above. I tried all sorts of things and eventually went back to just walking through the Magpie tutorial (which, of course, you suggested in your tutorial!). Even the basic Magpie tutorial didn't work, but at least I got a different error indicating that my web host was preventing me from opening outgoing sockets. Since I didn't want to pay anything for this, I did some research and figured out how to do the same thing using simplepie instead of magpie since simplepie uses cURL. After that, both a simple foreach worked on an items collection and by splitting up the data into an array and iterating through that... the bottom-line issue was that $rss->items was in fact empty because the fetch never returned anything.

    Thanks for your response!
     
  12. islamify

    islamify New Member

    Unable to limit number of stories through Magpie...

    I'm trying to limit the number of stories that show up in my facebook app, so I've added the following line to my rss.php: $items = array_slice($rss->items,0,5);
    According to all the magpie tutorials that I have read, that line should reduce the number of stories showing up to the first 5...but I still get like 20. Any help would be appreciated.

    <?php
    include('conf.php');
    //define('MAGPIE_CACHE_DIR', $magpie_cache_dir);
    define('MAGPIE_CACHE_ON', 0);
    //define('MAGPIE_CACHE_AGE', 600);

    require_once('rss/rss_fetch.inc');
    $rss = fetch_rss('http://feeds.feedburner.com/Islamifycom/PublishedNews/');
    $items = array_slice($rss->items,0,5);
    $fbml = '<fb:header decoration="no_padding">Islamify.com | Muslim Social News</fb:header><div style="margin:0px 0px 0px 0px;">';

    foreach ($rss->items as $item){
    $fbml .= '<div style="border-bottom: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 1px 5px 1px 5px;"><tr><td valign="top" width="80%"><a href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
    <meta name="medium" content="blog" />
    <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />

    <link rel="target_url" href="'.$item['link'].'" />
    </fb:share-button></td></tr></table></div>';
    $fbml .= '</div>';
    }
    $fbml .= '</div>';

    echo $fbml;

    ?>
     
  13. falko

    falko Super Moderator Howtoforge Staff

    Change
    Code:
    foreach ($rss->items as $item){
    to
    Code:
    foreach ($items as $item){
     
  14. islamify

    islamify New Member

    worked...

    worked like a charm. Much indebted to you.
     
  15. Linda Rosmunda

    Linda Rosmunda New Member

    When I sign in to my Facebook account I can view the news feed page fine, but as soon as i navigate away from this page and return to it, it is just blank.
    I did have Fan Check in My apps but that has since been deleted, and I also changed my password afterwords. would I still be having trouble with this now?
     

Share This Page