如何实现PubSubHubbub?

发布于 2024-09-26 07:39:58 字数 879 浏览 3 评论 0原文

我想知道如何在 PHP 站点中实现 PubSubHubbub 。我不明白。你能吗解释一下我? 我不明白这个主意。 发布者通知订阅者,订阅者——我的网站?

    <?php

// simple example for the PHP pubsubhubbub Subscriber
// as defined at http://code.google.com/p/pubsubhubbub/
// written by Josh Fraser | joshfraser.com | [email protected]
// Released under Apache License 2.0

include("PuSHSubscriber.php");

$hub_url = "http://pubsubhubbub.appspot.com";
$callback_url = "url to my site?";

$feed = "feed link";

// create a new subscriber
$s = new Subscriber($hub_url, $callback_url);

// subscribe to a feed
$s->subscribe($feed);
// unsubscribe from a feed
//$s->unsubscribe($feed);

?>

或者我应该在 $hub_url 上发布我的中心?

I am wondering how to implement PubSubHubbub in a PHP site.I don't understand it.Can you explain me?
I don't get the idea.
The publisher notifies the subscriber and the subscriber - my site?

    <?php

// simple example for the PHP pubsubhubbub Subscriber
// as defined at http://code.google.com/p/pubsubhubbub/
// written by Josh Fraser | joshfraser.com | [email protected]
// Released under Apache License 2.0

include("PuSHSubscriber.php");

$hub_url = "http://pubsubhubbub.appspot.com";
$callback_url = "url to my site?";

$feed = "feed link";

// create a new subscriber
$s = new Subscriber($hub_url, $callback_url);

// subscribe to a feed
$s->subscribe($feed);
// unsubscribe from a feed
//$s->unsubscribe($feed);

?>

Or on $hub_url I should post my hub?

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

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

发布评论

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

评论(2

愛上了 2024-10-03 07:39:58

您似乎是订阅者,这意味着您希望在 Feed 中有更新时收到通知。流程如下:

  1. 查找中心网址。 Feed 中应该有一个带有 rel="hub" 的 (或 )元素。 href 包含中心的 url。那里有许多不同的中心!

  2. 实现回调 URL。当有新内容可供您使用时,集线器将调用此 url(必须可从外部访问(因此,不是本地主机!)。它还应该实现验证机制(见下文)

  3. 执行对中心的订阅请求:这是对中心 URL 的 POST 请求(请参阅 1.),具有以下参数: hub.topic= hub.callback= hub.mode=subscribe hub.verify =sync(保持同步,因为这样更容易调试)。

  4. 集线器将向您的回调发送验证请求,带有 hub.verify_token 参数。然后,您的应用必须回显此参数才能验证订阅。

  5. 如果一切正常,集线器将返回 204,您就可以开始了。如果没有,它将返回 4XX,您应该检查正文,因为它包含失败原因的指示。

  6. 稍后,一旦订阅被确认,您将收到正文中包含更新内容的 POST 请求

  7. (您必须每天重新订阅。实际时间取决于中心告诉您的时间。)

看起来您使用了现有的库。它应该实现上面的所有步骤。然而,了解幕后发生的事情很重要,因此您可能想自己实现它。事情没那么复杂。确保您的回调可以从“外部”访问,并检查 $s->subscribe($feed); 实际上不会返回订阅的结果,因为这会有所帮助。

如果您需要更完整的 PubSubHubbub 教程,请查看此教程

祝你好运!

Looks like you're a subscriber, which means that you want to be notified upon updates in the feed. Here is the process :

  1. Find the hub url. There should be a <link> (or <atom:link>) element in the feed with rel="hub". The href contains the url of the hub. There are many different hubs out there!

  2. Implement a callback url. This url (which must be accessible from outside (so, not localhost!) will be called by the hub when new content is available for you. It should also implement the verification mechanism (see below)

  3. Perform the subscription request to the hub : it's a POST request to the hub url (see 1.) with the following params : hub.topic= hub.callback= hub.mode=subscribe hub.verify=sync (keep sync, as it's easier to debug).

  4. The hub will send a verification request to your callback, with a hub.verify_token param. Your app must then echo this param for the subscription to be validated.

  5. If all is fine, the hub will return 204 and you're good to go. If not, it will return a 4XX and you should check the body as it includes indications of what failed.

  6. Later, once the subscriptions is acknowledged, you will get POST requests with the content of the update in the body.

  7. (You have to re-subscribe every day. The actual time depends on what the hub tells you.)

Looks like you use an existing library. It should implement all the steps from above. Yet, it's something important to understand what's going on under the hood, so you may want to implement it yourself. It's not that complicated. Make sure that your callback is accessible from the "outside" and check that $s->subscribe($feed); doesn't actually return the outcome of the susbcription as it would help.

If you need a more complete PubSubHubbub tutorial, check this one.

Good luck!

月亮是我掰弯的 2024-10-03 07:39:58
  • $hub_url 是第 3 方中心的网址
  • $topic_url 是您订阅的“提要”
  • $callback_url 是您的网站上的网址当集线器获取新结果时,应使用新结果对服务器进行 ping 操作。

我希望这有帮助!

  • $hub_url is the url of the 3rd party hub
  • $topic_url is the 'feed' you're subscribing to
  • $callback_url is the url on your server that should be pinged with new results as the hub gets them.

I hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文