1

我正在尝试获取在 Twitter 上搜索某个词的用户列表,但到目前为止没有运气。这是我的代码:

$parameters = array('q' => '#puppy', 'count' => 2);
$results = $connection->get('search/tweets', $parameters);

//print_r($result);

foreach ($results as $data) {

?>

        <div id="update">
            <div id="left"><a href="https://twitter.com/#!/<?php echo $data->user->screen_name; ?>" target="_blank"/><img width="48px" height="48px" src="<?php echo $data->user->profile_image_url; ?>"/></a></div>
            <div id="right">
                <div class="user"><a href="https://twitter.com/#!/<?php echo $data->user->screen_name; ?>" target="_blank"/><?php echo $data->user->screen_name; ?></a>&nbsp;<?php echo $data->user->name; ?></div>
                <div class="detail">
                <?php echo $data->text; ?>
                </div>
            </div>
        </div>
<?php
}

这就是它的输出:

Notice: Undefined property: stdClass::$user in line 150
Trying to get property of non-object in line 150

我知道我正在以一种奇怪的方式访问该数组,我只是无法弄清楚它需要如何。

4

1 回答 1

1

对于可能需要此功能的任何人,只需以正确的方式从数组中获取正确的数据即可。这是我使用的代码:

        $parameters = array('q' => '#puppy', 'count' => 2);
        $results = $connection->get('search/tweets', $parameters);

        $resultsuser = $results->statuses[0]->user;

        $i = 0;
        foreach ($results->statuses as $data) {

            $user_screen_name = $data->user->screen_name;
            $user_profile_image_url = $data->user->profile_image_url;
            $user_text = $data->text;

        ?>

                <div id="update">
                    <div id="left"><a href="https://twitter.com/#!/<?php echo $user_screen_name; ?>" target="_blank"/><img width="48px" height="48px" src="<?php echo $user_profile_image_url; ?>"/></a></div>
                    <div id="right">
                        <div class="user"><a href="https://twitter.com/#!/<?php echo $user_screen_name; ?>" target="_blank"/><?php echo $user_screen_name; ?></a>&nbsp;<?php echo $user_screen_name; ?></div>
                        <div class="detail">
                        <?php echo $user_text; ?>

                        <hr/>
                        </div>
                    </div>
                </div>
        <?php
        $i++;
        }


        ?>
于 2013-05-19T15:16:23.210 回答