我目前正在使用此代码来获取我博客的订阅者数量:
$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被回显的整个文件)。关于为什么这不起作用的任何想法?
答案 0 :(得分: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
),因此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>
您确定使用的是正确的网址/ Feed吗?