PHP XML feed assembler works for every feed except Twitter

筅森魡賤 提交于 2019-12-25 02:43:26

问题


I'm trying to retrieve feeds from a twitter search to display on various parts of the site. I modified this function to do this yet it works for every feed a try it on except twitter.

function getFeed($feed_url) {

    $content = file_get_contents($feed_url);

    $x = new SimpleXmlElement($content);

    echo "<ul>";

    foreach($x->channel->item as $entry) {
        echo "
        <li>
          <a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>
        </li>";
        }
    echo "</ul>";
}

I am after only the content of the various associative posts. Here is a sample call.

<?php getFeed("feed://search.twitter.com/search.atom?q=berkshire+golf"); ?>

Any ideas,

Marvellous


回答1:


Twitter's search API is just a simple HTTP request, so your URL should be http:// and not feed:// if you're using file_get_contents

Edit:

You're also using .atom, use rss instead:

http://search.twitter.com/search.rss?q=berkshire+golf



来源:https://stackoverflow.com/questions/6001765/php-xml-feed-assembler-works-for-every-feed-except-twitter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!