我试图弄清楚如何获取 Twitter 用户的最新纬度和经度(从新的 Geo API 数据,即标签,您可以在我的 twitter 用户时间轴 xml 提要<geo:point>
中看到它们的样子)。我还需要从标签中检索该数据的年龄(以秒为单位) 。<created_at>
我正在尝试用 C 语言编写它以与mbed 微控制器一起使用,因此我不能使用任何大型库(理想情况下我不会使用任何库,但这可能是个坏主意)。mbed 站点建议了一些轻量级库- YAJL和 FastXML 似乎很有用 - 但我的 C 知识非常基础,我不确定如何继续。
假设我有将 twitter 用户时间线作为字符串检索到内存和/或磁盘(作为 JSON 或 XML)的代码,我应该如何继续?
目前我正在通过 PHP 在我的网络服务器上进行这种抓取,但我宁愿在 C 中完成它,因为我希望在完成后发布代码(而且我不希望我可怜的服务器被撞! ) PHP 看起来像这样:
<?php
date_default_timezone_set('UTC');
try {
$tweets = json_decode(file_get_contents("http://twitter.com/statuses/user_timeline.json?screen_name=".urlencode($_GET['screenname'])));
foreach($tweets as $tweet) {
if (is_array($tweet->geo->coordinates)) {
echo date("U") - strtotime($tweet->created_at);
echo ",{$tweet->geo->coordinates[0]},{$tweet->geo->coordinates[1]}";
break;
}
}
} catch (Exception $e) {
exit();
}
这工作得很好,但我不知道如何把它变成 C!有任何想法吗?
这是我期望处理的 XML 片段:
<statuses type="array">
<status>
<created_at>Sat Dec 12 22:25:17 +0000 2009</created_at>
<id>6611101548</id>
<text>Hello stackoverflow! This tweet is geotagged.</text>
<other tags/>
<geo>
<georss:point>52.946972 -1.182846</georss:point>
</geo>
</status>
<status ...>
</statuses>
(顺便说一句,mbed 很棒,尽管我缺乏 C 或电子学方面的高级知识,但我玩得很开心,它们在 Farnell 的库存价格为 32 英镑,绝对物有所值!)