php Facebook 取消了公共 RSS 提要;如何使用新的时间线获取 Facebook 页面 RSS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9709016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:28:33  来源:igfitidea点击:

Facebook killed Public RSS feeds; how to obtain a Facebook Page RSS with the new Timeline?

phprubyfacebookfacebook-graph-apirss

提问by ylluminate

I'm attempting to pull out a page feed to RSS from Facebook, however each time I attempt to try it, I get an error back in the XML with the following :

我试图从 Facebook 中提取到 RSS 的页面提要,但是每次我尝试尝试时,我都会在 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;
]]>

The URL I'm using is:

我使用的网址是:

https://www.facebook.com/feeds/page.php?id=<fb_id>&format=rss20&access_token=<my_page_token>

I don't have an age restriction set nor a country restriction:
enter image description here

我没有设置年龄限制或国家/地区限制:
在此处输入图片说明

Further, I've tried it with and without my access token.

此外,我已经尝试过使用和不使用访问令牌。

As noted in the comments below, the JSON URL is indeed working:

正如下面的评论中所指出的,JSON URL 确实有效:

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

What is going on here / how do I resolve the problem?

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

回答by stacey

Here are my directions.

这是我的方向。

  1. Go to facebook and right-click profile image to get URL and copy the ID
  2. Go here https://graph.facebook.com/ID_GOES_HERE
  3. Take the ID value that is listed on the resulting page and copy it
  4. Go here and paste the new ID https://www.facebook.com/feeds/page.php?id=ID_GOES_HERE&format=rss20
  5. Copy and paste URL into your feed reader
  1. 转到 Facebook 并右键单击个人资料图片以获取 URL 并复制 ID
  2. 去这里https://graph.facebook.com/ID_GOES_HERE
  3. 获取结果页面上列出的 ID 值并复制它
  4. 去这里粘贴新 ID https://www.facebook.com/feeds/page.php?id=ID_GOES_HERE&format=rss20
  5. 将 URL 复制并粘贴到您的 Feed 阅读器中

回答by lu1s

I got with the same problem. After looking for a solution I found that FB silently killed public RSS support. (see this postfrom Jesse Stay)

我遇到了同样的问题。在寻找解决方案后,我发现 FB 默默地扼杀了公共 RSS 支持。(见Jesse Stay 的这篇文章

I understood that I needed to call the API myself and construct the feed (I also need the feed to be parsed by a WP plugin and other stuff.

我知道我需要自己调用 API 并构建提要(我还需要通过 WP 插件和其他东西来解析提要。

So, first of all get an API key (also called app id) and download the PHP Facebook SDK.

因此,首先获取 API 密钥(也称为应用程序 ID)并下载 PHP Facebook SDK。

Then download the Universal Feed GeneratorPHP class. It will generate all the required headers and xml for you.

然后下载Universal Feed GeneratorPHP 类。它将为您生成所有必需的标头和 xml。

Your php script will be like this:

您的 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();

Note from the future (2013-07-09): Don't listen to my answer anymore. It's old. Facebook has a new API with new features on its query language so don't bother pulling feeds. Try to use their API in a more fun, intelligent way :)

未来注意事项(2013-07-09):不要再听我的回答了。它老了。Facebook 有一个新的 API,它的查询语言有新的特性,所以不要费心拉提要。尝试以更有趣、更智能的方式使用他们的 API :)

回答by tona b

When there's no page id to be found in the source page, I found the id through the "create a page" link, as in

当在源页面中找不到页面 id 时,我通过“创建页面”链接找到了 id,如

https://www.facebook.com/pages/create.php?ref_id=the_#_here

https://www.facebook.com/pages/create.php?ref_id=the_#_here

ahhhh... so good to have my rss feeds back! Thanks, everyone! :D

啊哈……我的 RSS 反馈太棒了!谢谢大家!:D

回答by antou

Two easy steps to get the RSS/Atom feed :

获取 RSS/Atom 提要的两个简单步骤:

This url generates an Atom feed, but you can change it.

此 url 生成一个 Atom 提要,但您可以更改它。

回答by Michelle Dear

For an easier way to find page id:

要更轻松地查找页面 ID:

Just view the source for your FB page (or timeline app, previously known as tab), and search for page_id. Replace it with the code provided.

只需查看您的 FB 页面(或时间线应用程序,以前称为选项卡)的源,然后搜索page_id. 用提供的代码替换它。