Twitter Oauth家庭时间线显示与PHP

时间:2010-04-27 08:40:16

标签: php twitter oauth

$ hometime = $ Twitter-> get_statusesHome_timeline();

致命错误:带有消息'SimpleXMLElement :: __ construct()的未捕获异常'Exception'要求参数1为字符串

<?php
        include 'EpiCurl.php';
        include 'EpiOAuth.php';
        include 'EpiTwitter.php';
        include 'key.php';

        $Twitter = new EpiTwitter($consumerKey, $consumerSecret);
        $oauthToken='xxxxxxxxxxxxxxxxxxxxxxx';
        $oauthSecret='xxxxxxxxxxxxxxxxxxxxxxxxx';

             // user switched pages and came back or got here directly, stilled logged in
             $Twitter->setToken($oauthToken,$oauthSecret);
             $user= $Twitter->get_accountVerify_credentials();

       echo "<img src=\"{$user->profile_image_url}\">";
       echo "{$user->name}";


        $hometime= $Twitter->get_statusesHome_timeline();

        $twitter_status = new SimpleXMLElement($hometime);
        foreach($twitter_status->status as $status){
            echo '<div class="twitter_status">';
            foreach($status->user as $user){
                echo '<img src="'.$user->profile_image_url.'" class="twitter_image">';
                echo '<a href="http://www.twitter.com/'.$user->name.'">'.$user->name.'</a>: ';
            }
            echo $status->text;
            echo '<br/>';
            echo '<div class="twitter_posted_at"><strong>Posted at:</strong> '.$status->created_at.'</div>';
            echo '</div>';
        }

             ?>

2 个答案:

答案 0 :(得分:0)

我最好的猜测是你可能已经关闭了警告(和通知)以及

$hometime= $Twitter->get_statusesHome_timeline();

调用不会返回任何xml而是“false”,因为它无法连接(或其他)。

您是否在通话后尝试打印$ hometime?

答案 1 :(得分:0)

$ hometime应该是一个状态对象数组。

尝试

<?php
$hometimeline = $Twitter->get_statusesHome_timeline();
foreach($hometimeline as $status){
    echo '<div class="twitter_status">';
    foreach($status->user as $user){
        echo '<img src="'.$user->profile_image_url.'" class="twitter_image">';
        echo '<a href="http://www.twitter.com/'.$user->name.'">'.$user->name.'</a>: ';
    }
    echo $status->text;
    echo '<br/>';
    echo '<div class="twitter_posted_at"><strong>Posted at:</strong> '.$status->created_at.'</div>';
    echo '</div>';
}