Quantcast
Channel: ryo.com » php
Viewing all articles
Browse latest Browse all 20

PubSubHubBubのpubに対応する

$
0
0

自前アプリでPubSubHubBubのpubに対応するのをやってみたので、とりあえずメモしたものをブログに載せときます。

0. 対象

PubSubHubBubのpubサイト、すなわちRSS2.0またはATOMフィードを出力するWebサイト/Webアプリケーション
(注意)
文中の
YOUR_RSS2_FEED_URLはpubサイトのRSS2.0フィードのURL
YOUR_ATOM_FEED_URLはpubサイトのATOMフィードのURL
を示す。
hubサイトとして http://pubsubhubbub.appspot.com/ を利用する

1. RSSフィード/ATOMフィードの修正

-1. RSS2.0フィードの場合

* rss要素にatomのNSを入れる
(例)
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
>

* atom:link rel=”self” と atom:link rel=”hub”を<channel>の中に入れる
<atom:link href="YOUR_RSS2_FEED_URL" rel="self" type="application/rss+xml" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />

-2. ATOMフィードの場合

* link rel=”self” と link rel=”hub”を入れる
<link rel="self" type="application/atom+xml" href="YOUR_ATOM_FEED_URL" />
<link rel="hub" href="http://pubsubhubbub.appspot.com" />

-3. フィードの確認

http://feedvalidator.org/ で確認
エラーではないが、

* line 12, column 62: Unregistered link relationship: hub [help]
<atom:link rel=”hub” href=”http://pubsubhubbub.appspot.com” />

こんなRecommendationsが出るが、気にしない、というかむしろ正しい。

-4. appspotでの確認

http://pubsubhubbub.appspot.com/publish
のPublishフォームにフィードのURLを入力し、Publishを行う。
下のPublisher Diagnosticsフォームに同じくフィードのURLを入力し、「Get info」を押して

Topic Details – YOUR_ATOM_FEED_URL
Could not find any record for topic URL: YOUR_ATOM_FEED_URL

みたいなメッセージがでる。
Livedoor ReaderなどのPubSubHubBub対応クライアントでフィードを購読し、Sub側に現れてもらう。
下のPublisher Diagnosticsフォームに同じくフィードのURLを入力し、「Get info」を押して情報が出力されればOK

2. アプリからPublish通知を送る

hubサイト http://pubsubhubbub.appspot.com/ に対して、以下のパラメータをもつPOSTリクエストを送信する。このPOSTリクエストは application/x-www-form-urlencoded形式のContent-Typeで送信する必要がある。

  • hub.mode : “publish”という文字列
  • hub.url : RSS2.0またはATOMフィードのURL

phpのcurl関数で書くとこんな感じ
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://pubsubhubbub.appspot.com/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTDATA, 'hub.mode=publish&hub.url='.urlencode('YOUR_ATOM_FEED_URL'));
curl_exec($ch);
curl_close($ch);

※ POSTDATAをarrayで渡すとapplication/x-www-form-urlencodedにならないハズなんで注意


Viewing all articles
Browse latest Browse all 20

Latest Images

Trending Articles





Latest Images