php – Facebook杀死公共RSS源;如何使用新的时间轴获取Facebook页面RSS?

前端之家收集整理的这篇文章主要介绍了php – Facebook杀死公共RSS源;如何使用新的时间轴获取Facebook页面RSS?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图从Facebook上提取RSSRSS,但是每次尝试尝试时,我会在 XML中返回以下错误信息:
<![CDATA[
This Feed URL is no longer valid. Visit this page to find the new URL,if you have access: &lt;a href=&quot;https://www.facebook.com/profile.PHP?id=<FB_ID>&quot;&gt;https://www.facebook.com/profile.PHP?id=<FB_ID>&lt;/a&gt;
]]>

我使用的URL是:

https://www.facebook.com/Feeds/page.PHP?id=<fb_id>&format=RSS20&access_token=<my_page_token>

我没有年龄限制和国家限制:

此外,我尝试了没有我的访问令牌.

如下面的评论所述,JSON URL确实有效:

https://graph.facebook.com/<page_name>/Feed&https://www.facebook.com/<page_name>/‌​Feed?access_token=<token>

这里发生了什么/如何解决问题?

我遇到同样的问题.寻找解决方案后,我发现FB默默地杀死了公共的RSS支持. (见Jesse Stay的 this post)

我明白,我需要自己调用API并构建Feed(我还需要由WP插件和其他东西解析的Feed.

所以,首先得到一个API密钥(也称为app id)并下载PHP Facebook SDK.

然后下载Universal Feed Generator PHP类.它将为您生成所有必需的标题和xml.

你的PHP脚本将是这样的:

require('lib/facebook.PHP'); // require your facebook PHP sdk
include("Feed_generator/FeedWriter.PHP"); // include the Feed generator Feedwriter file

$fb = new facebook(array(
    'appId' =>  'YOUR_APP_ID',// get this info from the facebook developers page
    'secret'=>  'YOUR_SECRET_KEY' // by registering an app
));
$response = $fb->api('/spreetable/Feed','GET'); // replace "spreetable" with your fb page name or username

// create the Feedwriter object (we're using ATOM but there're other options like RSS,etc)
$Feed = new FeedWriter(ATOM);

$Feed->setTitle('Spree Table'); // set your title
$Feed->setLink('http://spreetable.com/facebook/Feed.PHP'); // set the url to the Feed page you're generating

$Feed->setChannelElement('updated',date(DATE_ATOM,time()));
$Feed->setChannelElement('author',array('name'=>'Spree Table')); // set the author name

// iterate through the facebook response to add items to the Feed
foreach($response['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);
        }
}

// that's it... don't echo anything else,just call this method
$Feed->genarateFeed();

未来的注意事项(2013-07-09):不要再听我的回答了.老了Facebook有一个新的API,其查询语言具有新功能,因此不要打扰提取.尝试使用他们的API更有趣,聪明的方式:)

猜你在找的PHP相关文章