代码之家  ›  专栏  ›  技术社区  ›  RSM

使用PHP获取Twitter提要到我的网站

  •  3
  • RSM  · 技术社区  · 15 年前

    任何关于我如何做到这一点的建议都会很好。

    干杯

    2 回复  |  直到 15 年前
        1
  •  3
  •   Kieran Allen    15 年前

    还有一个内置的simplexml函数:

    // Parse the raw xml
    $xml    =    simplexml_load_file('http://twitter.com/statuses/user_timeline/{yourfeed}.rss');
    
    
    // Go through each tweet
    foreach ($xml->channel->item as $tweet)
    {
        echo $tweet->title . '<br />';
    }
    
        2
  •  1
  •   George Mandis    12 年前

    尝试库: http://dev.twitter.com/pages/libraries#php

    或者,如果出于某种原因这些看起来像是过度杀戮,那么通过cURL和simplexml\u load\u string加载提要。根据需要操作。

    这将显示您的最后一条推文:

    <?php
    
    $ch = curl_init("http://twitter.com/statuses/user_timeline/{yourtwitterfeed}.rss");
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    
    $data = simplexml_load_string(curl_exec($ch));
    curl_close($ch);
    
    echo $data->channel->item[0]->title;
    

    编辑