获取 Atom feed 并以 html 形式显示(google-api)
有人可以帮我解决这个问题吗? 我对 google-api 调用的返回结果有疑问,
我想将它们作为 html 回显,但 Firefox 一直显示提要页面。
在 IE 中,我收到一条错误消息,指出 xml 文档只能包含一个顶级元素 这一定是原子“feed”元素,所以我不明白。
我可以做些什么来改进这一点?
$response= curl_exec($ch);
curl_close($ch);
// Parse the response
$response= simplexml_load_string($response);
foreach($response->entry as $position)
{
echo "position: " . $position->title . "<br />";
//next would be the stockvalue, but I don't yet know how to get that
}
编辑
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 2",
);
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "http://finance.google.com/finance/feeds/default/portfolios/1/positions");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
编辑 我看到了我的错误 我没有使用
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
谢谢,理查德
Can someone help me out on this.
I have a problem with the return results from an google-api call
I want to echo them back as html, but firefox keeps displaying a feed page.
In IE, I get an error saying that an xml document can only contain one toplevel element
wich must be the atom "feed" element, so I don't get that.
What can I do to improve on this?
$response= curl_exec($ch);
curl_close($ch);
// Parse the response
$response= simplexml_load_string($response);
foreach($response->entry as $position)
{
echo "position: " . $position->title . "<br />";
//next would be the stockvalue, but I don't yet know how to get that
}
edit
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 2",
);
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "http://finance.google.com/finance/feeds/default/portfolios/1/positions");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
edit
I saw my mistake
I did not use
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
thanks, Richard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
var_dump()
您的$response
并查看里面有什么数据。我将使用
file_get_contents()
而不是CURL
。Try to
var_dump()
your$response
and look what data you have inside.And I will use
file_get_contents()
instead ofCURL
.