How to implement PubSubHubbub?

懵懂的女人 提交于 2019-11-30 00:54:05
Julien Genestoux

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!

  • $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!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!