0

我目前正在使用此代码来获取我博客的订阅者数量:

$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 正在回显的整个文件)。关于为什么这不起作用的任何想法?

4

1 回答 1

1

如果您$data在尝试使用 SimpleXMLElement 加载它之前先查看一下,您会看到它包含以下 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,因此 curl 遵循重定向...

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


实际上,当我尝试加载我之前发布的 HTML 代码部分中给出的 URL 时:

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>


您确定您使用的是正确的 URL/Feed 吗?

于 2010-04-24T21:12:26.880 回答