跳至正文

在文本中显示 Google Feed 订阅者数量

在文本中显示 Google Feed 订阅者数量

我们之前展示了如何以原始文本显示 Feedburner 提要计数但是,如果您最近将您的供稿从 Feedburner 迁移到 Google Feed,您会发现这些代码将不再有效。以下是解决方法,适用于那些想要以文本形式显示 Google Feed 订阅者数量以获得更好样式的用户。

以前的 Feedburner 代码……

此代码仅在您打算以文本形式显示Feedburner提要计数时才有效,但对于那些已经在 Google 提要上的人来说,需要进行一些更改。

1个
2个
3个
4个
5个
6个
7
8个
9
10
11
12
13
14
15
16
17
18
19
20
//get cool feedburner count
$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id";
 
//Initialize the Curl session
$ch = curl_init();
 
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);
 
//Execute the fetch
$data = curl_exec($ch);
 
//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
//end get cool feedburner count

解决方案

将第 2 行替换为:

1个
2个
//get cool feedburner count
$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id";

到以下内容:

1个
2个
//get cool feedburner count
$whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id";

完整代码

这是以文本形式显示 Google Feed 订阅者数量的完整代码集。请记住将feedburner-id(line:2) 替换为您的真实Feed ID。

1个
2个
3个
4个
5个
6个
7
8个
9
10
11
12
13
14
15
16
17
18
19
20
//get cool feedburner count
$whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id";
 
//Initialize the Curl session
$ch = curl_init();
 
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);
 
//Execute the fetch
$data = curl_exec($ch);
 
//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
//end get cool feedburner count

疑难解答

如果上面的代码不适合你,这里有一些可能性:

  • 仔细检查您是否已正确替换http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-idhttps://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id
  • 您是否替换feedburner-id为实际的 Feed ID?
  • SimpleXMLElements 需要 PHP5。如果什么都没有出现,很可能您的虚拟主机仍在使用 PHP4。您应该就升级事宜联系他们。

标签:

发表回复