0

我需要生成 RSS 提要并获取帖子的标题和网址等。我决定使用Superfeedr。所以在这种情况下,我是 Superfeedr 的订阅者。有回调(订阅者 URL)字段来获取数据,但我不知道应该在回调文件中写什么。我在网上研究了示例代码,但我没有发现任何关于示例代码的信息。顺便说一句,我想在 PHP 中执行此过程。因此,如果您知道我需要写入此文件的内容,请发表评论。

4

2 回答 2

2

John, I think you got it... which is good. Now, what to write in your PHP: this callback url (your PHP file) will be called in 2 different cases:

  1. to verify your intent (to confirm that you want to subscribe)
  2. to notify you of new content.

I'm no PHP person, but I'll dscribe the algorithm for you

To differentiate between the two, you just have to look at the type of request. If it's a GET request, then, it's the verification of intent, and if it's a POST request, then it's the notification of new content.

If it's the verification of content, you just have to echo the hub.challenge provided as a GET param (I believe echo $_GET['hub.challenge']; should work). You should also verify that you really want to the subscription, but that the logic of your app and I don't know it (most people just look up the $_GET['hub.topic'] in their database and if it's there, echo the challenge. If not, echo something else.

If it's the notification of new content, it's a bit more complex. You have to access the BODY of the HTTP request (again, not sure how PHP does it, but I'm sure somebody can help), then, parse it to extract the title and urls, and handle them as you would want (most people will save that in their databases).

I hope this helps!

于 2012-01-08T18:48:13.103 回答
0

我在 php 中使用此代码。希望它可以帮助某人

<?php
  if(isset($_Get["hub_challenge"])){
   echo $_Get["hub_challenge"];
   return;
}
于 2014-12-10T13:47:43.503 回答