
<?xml version="1.0" encoding="UTF-8"?>
<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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OrzDream &#187; FeedSky</title>
	<atom:link href="http://orzdream.com/tag/feedsky/feed/" rel="self" type="application/rss+xml" />
	<link>http://orzdream.com</link>
	<description>冏一个世界 冏一个梦想 Orz World Orz Dream</description>
	<lastBuildDate>Mon, 21 May 2012 06:42:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>显示 FeedSky,FeedBurner,Google Feed 的文本统计数字的方法</title>
		<link>http://orzdream.com/2009/01/display-feedsky-feerburner-googlefeed-subscriber-count-in-text/</link>
		<comments>http://orzdream.com/2009/01/display-feedsky-feerburner-googlefeed-subscriber-count-in-text/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 15:47:49 +0000</pubDate>
		<dc:creator>NetPuter</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[FeedBurner]]></category>
		<category><![CDATA[FeedSky]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://orzdream.com/?p=165</guid>
		<description><![CDATA[有些时候，为了页面的样式，或许你需要显示 FeedSky,FeedBurner,Google Feed 的文本统计数字。如何实现呢？其实我们可以利用强大的 API 调用 RSS 托管商的文本统计数字。 FeedSky Shawn 童鞋已经提供了显示 FeedSky 的文本统计数字的方法（原文地址），相关代码如下（把代码中的 feedsky-id 改为你的 Feed@FeedSky 的名称）： 1 2 3 4 5 &#60;?php $xml = simplexml_load_file&#40;'http://www.feedsky.com/rpc/feed_statistic_xml.php?u=feedsky-id'&#41;; $node = $xml-&#62;xpath&#40;'/month/day[last()]'&#41;; foreach&#40;$node as $n&#41;&#123;echo $n&#91;'subcount'&#93;;&#125; ?&#62;位读者 FeedBurner 这个方法是 NetPuter 参考 Shawn 的方法实现的，算是准原创吧。其中 API 的地址是在这里发现的，相关代码如下（同样，把代码中的 feedburner-id 改为你的 Feed@FeedBurner 的名称）： 1 2 3 4 5 &#60;?php $xml = simplexml_load_file&#40;'http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id'&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>有些时候，为了页面的样式，或许你需要显示 FeedSky,FeedBurner,Google Feed 的文本统计数字。如何实现呢？其实我们可以<strong>利用强大的 API 调用 RSS 托管商的文本统计数字</strong>。</p>
<h2>FeedSky</h2>
<blockquote><p>
<a href="http://ishawn.net/">Shawn </a>童鞋已经提供了显示 FeedSky 的文本统计数字的方法（<a href="http://ishawn.net/tips/feedsky-subscription-number-code.html">原文地址</a>），相关代码如下（把代码中的 <strong>feedsky-id</strong> 改为你的 Feed@FeedSky 的名称）：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.feedsky.com/rpc/feed_statistic_xml.php?u=feedsky-id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/month/day[last()]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subcount'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>位读者</pre></td></tr></table></div>

</blockquote>
<h2>FeedBurner</h2>
<blockquote><p>
这个方法是 NetPuter 参考 Shawn 的方法实现的，算是<strong>准原创</strong>吧。其中 API 的地址是在<a href="http://www.hongkiat.com/blog/display-google-feed-subscriber-count-in-text/">这里</a>发现的，相关代码如下（同样，把代码中的 <strong>feedburner-id</strong> 改为你的 Feed@FeedBurner 的名称）：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/rsp/feed/entry'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'circulation'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span> Readers</pre></td></tr></table></div>

</blockquote>
<h2>Google Feed</h2>
<blockquote><p>
由于 FeedBurner 已被 Google 收购，因此调用方法也差不多，代码如下（还是，把代码中的 <strong>googlefeed-id</strong> 改为你的 Feed@FeedBurner 的名称）：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=googlefeed-id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/rsp/feed/entry'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'circulation'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span> Readers</pre></td></tr></table></div>

</blockquote>
<h2>最终效果以及相关注意</h2>
<blockquote><p>
因为 OrzDream 是由 FeedSky 托管的，也有由 FeedBurner 托管的，但是几乎没有数字，所以借用一下 <a href="http://wpchina.org/">WPChina.org</a> 和<a href="http://www.essentialblog.cn/">精品博客</a>的订阅统计。<br />
<strong>图像版：</strong></p>
<blockquote><p>
截止至昨天， OrzDream 已经有<img src="http://www.feedsky.com/feed/netputer/sc/gif" />，<br />
WPChina.org 有<img src="http://feeds.feedburner.com/~fc/wordpresschina" />，<br />
精品博客有<img src="http://feedproxy.google.com/~fc/e-blog" />。
</p></blockquote>
<p><strong>文本版：</strong></p>
<blockquote><p>
截止至昨天， OrzDream 已经有<?php $xml = simplexml_load_file('http://www.feedsky.com/rpc/feed_statistic_xml.php?u=netputer');$node = $xml->xpath('/month/day[last()]');foreach($node as $n){echo $n['subcount'];} ?>位读者， WPChina.org 有<?php<br />
$xml = simplexml_load_file('http://api.feedburner.com/awareness/1.0/GetFeedData?uri=wordpresschina');$node = $xml->xpath('/rsp/feed/entry');foreach($node as $n){echo $n['circulation'];} ?> Readers ，精品博客有<?php $xml = simplexml_load_file('https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=e-blog');$node = $xml->xpath('/rsp/feed/entry');foreach($node as $n){echo $n['circulation'];} ?> Readers 。
</p></blockquote>
<p><strong>几点注意：</strong></p>
<ol>
<li>建议大家在使用代码的时候 Cache 一下，帮助 RSS 托管商和地球节省资源。有关 Cache 可以参考 WordPress 官方 Codex 的<a href="http://codex.wordpress.org/Function_Reference/WP_Cache"><strong>详细内容</strong></a>。</li>
<li>关于显示 FeedBurner,Google Feed 的文本统计数字的方法中，用到 <strong>SimpleXMLElements</strong> 这个玩意儿，它生存在 <strong>PHP5</strong> 环境中。如果你的 Blog 还是生存在 PHP4 环境的话，就无法使用以上显示 FeedBurner,Google Feed 的文本统计数字了。</li>
<li>不知道为什么，精品博客的订阅统计图标和文本有很大出入。此外， FeedSky 和 FeedBurner 也是图标和文本有出入（但是不大），我想应该是因为<strong>图标是一天更新一次，而 API 是即时更新的</strong>吧（可以看看它们的 API 的内容），你觉得呢？</li>
</ol>
</blockquote>
<p>PS1：一开始我是用 HONGKIAT.COM 的<a href="http://www.hongkiat.com/blog/display-google-feed-subscriber-count-in-text/">方法</a>显示 FeedBurner,Google Feed 的文本统计数字的，但发现不可行。后来在和 <a href="http://blog.guaniu.com">Leeiio</a> 的扯淡过程中<strong>突发灵感</strong>，其结果也就是上文的内容啦。折腾成功的感觉真<strong>爽</strong>！<br />
PS2：参考资料：《<a href="http://www.ibm.com/developerworks/cn/xml/x-simplexml.html">PHP 中的 SimpleXML 处理</a>》</p>
<ul class="related_post"><li><a href="http://orzdream.com/2009/08/feedburner-more-subscription-xml/" title="让 FeedBurner 联姻国产 RSS 阅读器">让 FeedBurner 联姻国产 RSS 阅读器</a> (17)</li><li><a href="http://orzdream.com/2008/08/maxthon2-feed-powerful/" title="让你家马桶更加舒服——增强Maxthon2的Feed订阅功能!">让你家马桶更加舒服——增强Maxthon2的Feed订阅功能!</a> (0)</li><li><a href="http://orzdream.com/2009/10/netputweets-guide/" title="奶瓶腿简明架设教程 + Q&#038;A">奶瓶腿简明架设教程 + Q&#038;A</a> (32)</li><li><a href="http://orzdream.com/2009/04/google-gwt-and-mirror/" title="用 Google 的新梯子和镜子翻墙吧">用 Google 的新梯子和镜子翻墙吧</a> (37)</li><li><a href="http://orzdream.com/2009/03/chi-mp-tips/" title="Chi.mp 驯服小小贴士">Chi.mp 驯服小小贴士</a> (31)</li></ul><hr />
<p><small>© NetPuter for <a href="http://orzdream.com">OrzDream</a>, 2009. |
<a href="http://orzdream.com/2009/01/display-feedsky-feerburner-googlefeed-subscriber-count-in-text/">查看原文</a> |
<a href="http://orzdream.com/2009/01/display-feedsky-feerburner-googlefeed-subscriber-count-in-text/#comments">发表评论</a> | 
<a href="https://twitter.com/netputer">Follow @NetPuter</a>
<br/>
Tags: <a href="http://orzdream.com/tag/feedburner/" rel="tag">FeedBurner</a>, <a href="http://orzdream.com/tag/feedsky/" rel="tag">FeedSky</a>, <a href="http://orzdream.com/tag/google/" rel="tag">Google</a>, <a href="http://orzdream.com/tag/rss/" rel="tag">RSS</a>, <a href="http://orzdream.com/tag/tour/" rel="tag">教程</a><br/>
</small>]]></content:encoded>
			<wfw:commentRss>http://orzdream.com/2009/01/display-feedsky-feerburner-googlefeed-subscriber-count-in-text/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>

