获取 Atom feed 并以 html 形式显示(google-api)

发布于 2024-08-16 05:15:20 字数 953 浏览 4 评论 0原文

有人可以帮我解决这个问题吗? 我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2024-08-23 05:15:20

尝试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 of CURL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文