William H
William H

Reputation: 241

Twitter OAuth - Get values from Array

I'm attempting to get a list of users who searched a term on Twitter and so far no luck. Here's my code:

$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
}

and this is what it outputs:

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

I know I'm accessing that array in a weird way, I just can't figure out how it needs to be.

Upvotes: 1

Views: 903

Answers (1)

William H
William H

Reputation: 241

For anyone out there who may be needing this, it was just a matter of getting the right data from the array in the right way. Here's the code I used:

        $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++;
        }


        ?>

Upvotes: 1

Related Questions