Superfeedr的回调文件中应该写什么?

发布于 2024-12-25 05:36:18 字数 251 浏览 4 评论 0原文

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

I need to generate RSS feed and get title and urls of the posts and so on. I decided to use Superfeedr for it. So in this situation, I'm a subscriber in Superfeedr. There is callback (the subscriber URL) field to get data, but I don't know what should be written in callback file. I researched the net for example code, but I found nothing about example code. BTW, I want to do this process in PHP. So if you know what should I need write to this file, please comment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2025-01-01 05:36:18

约翰,我想你明白了……这很好。现在,在 PHP 中编写什么:此回调 url(您的 PHP 文件)将在两种不同的情况下被调用:

  1. 验证您的意图(确认您想要订阅)
  2. 以通知您新内容。

我不是 PHP 人员,但我会为您描述该算法。

要区分这两者,您只需查看请求的类型即可。如果是GET请求,那么就是意图验证,如果是POST请求,那么就是新内容通知。

如果是内容验证,您只需回显作为 GET 参数提供的 hub.challenge (我相信 echo $_GET['hub.challenge']; 应该有效)。您还应该验证您是否确实想要订阅,但您的应用程序的逻辑我不知道(大多数人只是在中查找 $_GET['hub.topic']他们的数据库,如果存在,则回显挑战。如果没有,则回显其他内容。

如果是新内容的通知,则必须访问 HTTP 请求的正文(同样,不确定 PHP 是如何做的)。它,但我相信有人可以help),然后解析它以提取标题和网址,并按照您的意愿处理它们(大多数人会将其保存在他们的数据库中)

我希望这会有所帮助!

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!

小矜持 2025-01-01 05:36:18

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

<?php
  if(isset($_Get["hub_challenge"])){
   echo $_Get["hub_challenge"];
   return;
}

I'm using this code in php. Hope it helps someone

<?php
  if(isset($_Get["hub_challenge"])){
   echo $_Get["hub_challenge"];
   return;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文