推特api php foreach循环不适用于用户推特


Twitter api php foreach loop not working for users tweets

我正在使用twitter api php abraham libary,并试图循环浏览用户的tweet,但我遇到了麻烦。

我正在让所有用户使用这个从家庭时间线推特。

$content = $connection->get('statuses/home_timeline');
echo '<pre>',print_r($content),'</pre>';

如果我打印出数组。。。我明白了。

Array ( [0] => stdClass Object (    [created_at] => Tue Feb 10 15:31:07 +0000 2015 [id] => 565171109470171136 [id_str] => 565171109470171136 [text] => We are human beings not human doings – let’s start acting like it & take the time simply to be http://t.co/i4HAnApQxp http://t.co/3qSXA4D1qY [source] => Hootsuite [truncated] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => stdClass Object ( [id] => 8161232 [id_str] => 8161232 [name] => Richard Branson [screen_name] => richardbranson [location] => [profile_location] => [description] => Tie-loathing adventurer, philanthropist & troublemaker, who believes in turning ideas into reality. Otherwise known as Dr Yes at @virgin! [url] => http://t.co/pWM2y98gTu [entities] => stdClass Object (

如何使用forech循环从std类对象中获取名称?

我试过了,但不起作用??

foreach($content['user'] as $tweets) {
echo $tweets['name'] . '<br />';
}

任何帮助都是好的:)

好的,这似乎奏效了。。谢谢你的帮助

foreach($content as $tweets) {
echo $tweets->user->name . '<br />';
echo $tweets->text . '<br />';
}

您需要做的是:;

foreach($content as $tweets) {
    foreach($tweets['user'] as $user) {
        echo $user['name'] . '<br />';
    }
}