如何实现PubSubHubbub? [英] How to implement PubSubHubbub?

查看:95
本文介绍了如何实现PubSubHubbub?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在PHP网站中实现 PubSubHubbub .你能解释一下我吗? 我不知道. 发布者通知订阅者和订阅者-我的网站?

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 | josh@eventvue.com
// 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上发布我的中心?

Or on $hub_url I should post my hub?

推荐答案

您似乎是订阅者,这意味着您希望在Feed中进行更新时收到通知.这是过程:

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

  1. 找到中心网址.资讯提供中的rel ="hub"应该有一个<link>(或<atom:link>)元素. href包含中心的URL.有很多不同的枢纽!

  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!

添加回调网址.当您可以使用新内容时,集线器将调用此url(必须可以从外部访问(因此,不是localhost!)).它还应实现验证机制(见下文)

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)

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

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).

中心将通过hub.verify_token参数将验证请求发送到您的回调.然后,您的应用必须回显此参数,才能验证订阅.

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.

如果一切正常,集线器将返回204,您一切顺利.如果不是,它将返回4XX,并且您应该检查正文,因为它包含失败原因的指示.

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.

稍后,在确认订阅后,您将收到带有正文更新内容的POST请求.

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

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

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

好像您使用的是现有库. 应该执行上面的所有步骤.但是,了解幕后情况很重要,因此您可能想自己实施.没那么复杂.确保您的回调可以从外部"访问,并检查$s->subscribe($feed);确实没有返回怀疑的结果,因为这样做会有所帮助.

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.

如果您需要更完整的PubSubHubbub教程,请选中该内容.

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

祝你好运!

这篇关于如何实现PubSubHubbub?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆