Twitter的api PHP的foreach循环不工作的用户鸣叫
问题描述:
我使用twitter api php亚伯拉罕库利亚,我试图通过用户的tweets循环,但我有麻烦。Twitter的api PHP的foreach循环不工作的用户鸣叫
我正在使用此功能从家庭时间线获取所有用户的推文。
$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 (
如何从std类对象使用forech循环获取名称?
我试过这个,但它不工作?
foreach($content['user'] as $tweets) {
echo $tweets['name'] . '<br />';
}
任何帮助将是不错的:)
答
你需要做的这是什么;
foreach($content as $tweets) {
foreach($tweets['user'] as $user) {
echo $user['name'] . '<br />';
}
}
答
确定这似乎对你的帮助
foreach($content as $tweets) {
echo $tweets->user->name . '<br />';
echo $tweets->text . '<br />';
}
谢谢合作..thank你...但我只是去尝试,并没有工作:(.....我需要循环[created_at] [文本]和用户 - > [名称] ....因为它是一个stdclass对象,我需要循环$键值?如果是的话,我会怎么做呢?? :( – 2015-02-10 17:30:42