【发布时间】:2011-04-07 03:54:47
【问题描述】:
我是 API 的新手,就像今天一样。我已经学会了如何简单地调用 twitter api xml 数据并从帖子中提取某些内容。但我的问题是我似乎无法弄清楚如何在 Twitter API 中提取地理或坐标并将其显示或存储为变量。
<html>
<?php
$xmldata = 'http://twitter.com/statuses/user_timeline/allencoded.xml';
$open = fopen($xmldata, 'r');
$content = stream_get_contents($open);
fclose($open);
$xml = new SimpleXMLElement($content);
?>
<?php
$geo = $xml->status[0]->coordinates->georss:point; //<---PROBLEM POINT!!!!
?>
<body>
<table>
<tr>
<td><img src="<? echo $xml->status[0]->user->profile_image_url; ?>" /></td>
<td>
<? echo $xml->status[0]->text; ?> at <? echo $xml->status[0]->created_at; ?> by <? echo $xml->status[0]->user->name; ?>
</td>
<td>
GEO IS AT:<? echo $geo; ?>
</td>
</tr>
</table>
</body>
</html>
当我运行代码时,我得到: 解析错误:语法错误,第 11 行 C:\inetpub\vhosts\allencoded.com\httpdocs\twitter.php 中的意外 ':'
当我删除第 11 行的代码时,一切正常。
【问题讨论】:
-
georss 是一个命名空间。 stackoverflow.com/questions/5517887/… 和 devzone.zend.com/node/view/id/688#Heading3 应该会有所帮助。
-
嘿,只是想警告你,你非常接近被禁止在 SO 上提问。不要删除带有答案的问题并开始回答自己以躲避即将到来的禁令。
标签: php api twitter geolocation