2010-04-24 56 views
0

我目前使用此代码来获取用户到我的博客数量:获取feedburner订户的数量?

$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/DesignDeluge"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_URL, $whaturl); 
$data = curl_exec($ch); 
curl_close($ch); 
$xml = new SimpleXMLElement($data); 
$fb = $xml->feed->entry['circulation']; 

但是当我回声$ fb的它不工作(即$ FB整个文件被呼应上没有按” t出现)。任何想法,为什么这不工作?

回答

1

如果你想用的SimpleXMLElement加载它之前看一看$data,你会看到它包含了HTML代码以下部分:

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> 
<TITLE>301 Moved</TITLE></HEAD><BODY> 
<H1>301 Moved</H1> 
The document has moved 
<A HREF="http://feedburner.google.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/DesignDeluge">here</A>. 
</BODY></HTML> 

那么,有没有办法,你会发现你要找的在那里;-)


一个解决方案是使用CURLOPT_FOLLOWLOCATION选项(见curl_setopt,所以卷曲如下redirecti ons ...

...但是这似乎也不起作用。


其实,当我尝试加载在我张贴的HTML代码的部分中给出的网址前面:

http://feedburner.google.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/DesignDeluge 

我只得到下面的XML作为回报:

<?xml version="1.0" encoding="utf-8" ?> 
<rsp stat="fail"> 
    <err code="2" msg="This feed does not permit Awareness API access" /> 
</rsp> 


您确定您使用的是正确的网址/供稿吗?

+0

啊,事实证明有两件事情是错误的:我所遵循的教程过时了,所以URL错了,我也必须自己启用对API的访问。谢谢! – williamg 2010-04-24 21:30:26

+0

不客气:-)很高兴你发现了什么导致了问题:-) – 2010-04-24 21:52:16