Twitter api php foreach循环不适用于用户的推文

时间:2015-02-10 16:06:12

标签: php twitter tweets tweetstream

我正在使用twitter api php abraham libary,我正在尝试遍历用户的推文,但我遇到了麻烦。

我使用此功能从家庭时间线获取所有用户的推文。

$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 />';

}

任何帮助都会很好:)

2 个答案:

答案 0 :(得分:1)

好的,这似乎有用..谢谢你的帮助

foreach($content as $tweets) {

echo $tweets->user->name . '<br />';

echo $tweets->text . '<br />';

}

答案 1 :(得分:0)

你需要做的就是这个;

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