使用 PHP cURL 和 FeedBurner API 获取 FeedBurner 阅读器统计信息

Web 2.0 革命中我最喜欢的部分是丰富的 API。每个人都有一个:Digg、Feedburner、Pownce、Flickr、Google Maps 等。FeedBurner 提供了一个可爱的“Awareness API”,允许您从您的 FeedBurner 帐户中提取统计数据。以下是使用 PHP cURL 的方法。

PHP

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,'http://api.feedburner.com/awareness/1.0/GetFeedData?id=#######');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);

//execute post
$content = curl_exec($ch);

$subscribers = get_match('/circulation="(.*)"/isU',$content);

echo 'Subscribers:  '.$subscribers;

//close connection
curl_close($ch);


/* helper: does the regex */
function get_match($regex,$content)
{
	preg_match($regex,$content,$matches);
	return $matches[1];
}

就这么简单。更妙的是,我讨厌 FeedBurner 的“徽章”,而且我可以随心所欲地操纵上述代码的结果。单击此处了解有关 FeedBurner 的 Awareness API 以及您可以提取的有关您的 Feed 的信息的更多信息。

赞(0) 打赏

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏