0

好的,所以按照我在 StackOverflow 上的另一篇文章中找到的一些说明,我构建了一个脚本来获取粉丝页面提要并将其转换为 RSS2 提要。但是,脚本需要进行一些更改,而且我不是世界上最好的程序员,所以我需要一点帮助。

我收到此错误:

警告:在第 48 行的 feed.php 中为 foreach() 提供的参数无效

我不确定无效的论点是什么。

<?

// error reporting
echo '<pre>';
ini_set('display_errors', 'on');
error_reporting(E_ALL);

// require your facebook php sdk
require('./facebook/facebook.php'); 

// include the feed generator feedwriter file                   
include("./feed/FeedWriter.php");                       


// config secret key and appid
$config = array(
'appId' =>  '',                             
'secret'=>  ''      
);

// Initialize
$facebook = new Facebook($config);

// Set Apps Permissions Request
$permission_scope = "";

   // get users access token
$access_token = $facebook->getAccessToken();

    // get page post
    $feed_url = 'https://www.facebook.com/Ritualdubstep/feed?access_token='.$access_token;
    $feed_json = file_get_contents($feed_url);
    $feed_data = json_decode($feed_json);

// create the feedwriter object 
$feed = new FeedWriter(RSS2);

$feed->setTitle('Ritual Dubstep'); // set your feed title
$feed->setLink('https://www.facebook.com/Ritualdubstep'); // set the url to the feed page you're generating

$feed->setChannelElement('updated', date(DATE_RSS , time()));
$feed->setChannelElement('author', array('name'=>'Ritual Dubstep SF')); // set the author name

// iterate through the facebook response to add items to the feed
foreach($feed_data['data'] as $entry){
    if(isset($entry["message"])){
        $item = $feed->createNewItem();
        $item->setTitle($entry["from"]["name"]);
        $item->setDate($entry["updated_time"]);
        $item->setDescription($entry["message"]);
        if(isset($entry["link"]))
            $item->setLink(htmlentities($entry["link"]));

        $feed->addItem($item);
        }
}

// generate feed
$feed->genarateFeed();
?>
4

1 回答 1

0

通常这意味着foreach调用中的第一个参数(在这种情况下$feed_data['data'])不是有效的数组。

在运行进入循环之前确保$feed_data['data']存在 ( isset($feed_data['data'])) 并且它是一个数组 ( )。is_array($feed_data['data'])foreach

而且 - 正如评论中提到的变形者- 您可能希望在var_dump($feed_data['data'])开始循环之前开始故障排除foreach以查看正在生成的内容。

于 2012-12-04T01:43:06.553 回答