2012-05-16 30 views
1

我使用simplepie獲取我的Facebook粉絲頁面的rss,並且它的工作正常,只是它重複了幾次所有通過RSS在Facebook粉絲頁上插入的帖子的圖像對於我用來在Facebook上直接獲取所有behance更新的頁面。使用SIMPLEPIE獲取Facebook粉絲頁面RSS

不知道如何用simplepie API做一個合適的jsfiddle,所以除了我現在的代碼之外不能顯示出多少東西。

<?php 

// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc. 
require_once('php/simplepie.inc'); 

// We'll process this feed with all of the default options. 
$feed = new SimplePie(); 

// Set which feed to process. 
$feed->set_feed_url('http://www.facebook.com/feeds/page.php?format=rss20&id=242469109162998'); 

// Run SimplePie. 
$feed->init(); 

// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it). 
$feed->handle_content_type(); 

// Let's begin our XHTML webpage code. The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag. 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<title>Sample SimplePie Page</title> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
</head> 
<body> 

<div id="getall"> 

<?php 
/* 
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop. 
*/ 
foreach ($feed->get_items() as $item): 
?> 

    <div class="item"> 
     <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2> 
     <p><?php echo $item->get_description(); ?></p> 
     <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p> 
    </div> 

<?php endforeach; ?> 

</div> 

什麼你們有什麼意見?任何工作?

回答

0

爲什麼不使用php sdk並通過api調用獲取feed?

# After de facebook object instantiation 
$feedArray = $facebook->api('pageID/feed'); 

然後,您只將foreach應用到$ feedArray,然後按需要顯示它。