【问题标题】:Twitter api php foreach loop not working for users tweetsTwitter api php foreach循环不适用于用户推文
【发布时间】:2015-04-10 18:07:53
【问题描述】:

我正在使用 twitter api php abraham 库,我正在尝试循环浏览用户的推文,但我遇到了麻烦。

我正在使用这个从主时间线获取所有用户的推文。

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

}

任何帮助都会很好:)

【问题讨论】:

    标签: php twitter tweets tweetstream


    【解决方案1】:

    好的,这似乎有效..谢谢您的帮助

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

    【讨论】:

      【解决方案2】:

      你需要做的是这个;

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

      【讨论】:

      • 谢谢...但我只是尝试过,但没有成功:(.....我需要循环 [created_at] [text] 和 user->[name] ....因为它是一个 stdclass 对象,我需要循环 $key 值吗??如果是这样,我该怎么做??:(
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多