来自Twitter的PHP XML提要使用情况


PHP XML feed usage from Twitter

下面的代码应该从Twitter获取xml提要并返回结果。

<?php
$xml = simplexml_load_file('https://api.twitter.com/1/statuses/user_timeline/QuiteCheesedOff.xml?count=6');
$tweets = $xml->xpath("/statuses/status");
foreach($tweets as $tweet) {
    $text = $tweet->text;
    $date = $tweet->created_at;
    echo '<div>' . $text . '</div>' . '<b>' . $date . '</b>';
}
?>

它返回的是这个

警告:simplexml_load_file (https://api.twitter.com/1/statuses/user_timeline/QuiteCheesedOff.xml?count=6)(函数。simplexml-load-file]: failed to open stream: HTTP request失败了!HTTP/1.0 400错误请求/home/divethe1/public_html/robin-knight.com/wp-content/themes/RIKsoft/index.php第142行

您可以尝试使用DOMDocument->load($url)。Twitter提要的URL也可以不使用SSL,如果SSL给您带来麻烦并且您不需要安全版本,请尝试使用。

相关文章: