如何处理/使用Twitter API的stdClass对象?

时间:2010-10-31 06:31:07

标签: php twitter

等等,你不需要阅读全部内容:)只需向下滚动,看看我问过什么。

stdClass Object
    (
    [friends_count] => 54
    [description] => i'TS THE digiTAL vERSiOn 0b devilZ! tECH & mUUsic fReak.

    sImpLE buT.......! 
    [screen_name] => 2020Volt
    [profile_sidebar_border_color] => 181A1E
    [status] => stdClass Object
    (
    [in_reply_to_user_id_str] => 83300174
    [place] => 
    [coordinates] => 
    [contributors] => 
    [in_reply_to_screen_name] => Anik1990
    [geo] => 
    [retweet_count] => 
    [source] => Seesmic Web
    [retweeted] => 
    [in_reply_to_status_id] => 29180026185
    [created_at] => Sat Oct 30 13:04:53 +0000 2010
    [in_reply_to_user_id] => 83300174
    [truncated] => 
    [in_reply_to_status_id_str] => 29180026185
    [id] => 29181306201
    [id_str] => 29181306201
    [favorited] => 
    [text] => @Anik1990 its just my point of view man.....
    )

    [geo_enabled] => 1
    [follow_request_sent] => 
    [time_zone] => Dhaka
    [favourites_count] => 1
    [verified] => 
    [notifications] => 
    [profile_background_color] => 1A1B1F
    [url] => http://techysafi.wordpress.com
    [lang] => en
    [profile_use_background_image] => 1
    [created_at] => Tue Sep 21 15:28:38 +0000 2010
    [profile_text_color] => 666666
    [location] => Dhaka,Bangladesh[listed_count] => 6
    [protected] => 
    [statuses_count] => 1962
    [profile_background_image_url] => http://s.twimg.com/a/1288217225/images/themes/theme9/bg.gif
    [profile_link_color] => 2FC2EF
    [name] => Tech Freak Satan
    [show_all_inline_media] => 
    [following] => 
    [profile_image_url] => http://a1.twimg.com/profile_images/1146520409/SDC11078_normal.jpg
    [id] => 193332358
    [id_str] => 193332358
    [contributors_enabled] => 
    [profile_background_tile] => 
    [utc_offset] => 21600
    [profile_sidebar_fill_color] => 252429
    [followers_count] => 60
    )

现在我的问题是如何将[text]变成像$ tweet这样的变量?还有[名字]。因为我想将它们存储在mysql上,所以我需要检索[text]&的值。 [姓名]!

$ sdjkf->状态 - >文字;这不是什么回报!

我在这里看到了一篇相关的帖子How would i access the properties in this object? Twitter API,但我的情况有点不同。如果您愿意,只需浏览此链接即可。

(我请你原谅,请不要把我视为专业人士,不管你要说什么,完全说清楚......我知道我很蠢: - )

提前致谢

2 个答案:

答案 0 :(得分:1)

假设你有一个stdClass对象(如上所列)存储在一个名为$response的php变量中,你可以将text属性放入一个名为{{1}的php变量中像这样:

$tweet

同样,名称为:

$tweet = $response->status->text;

答案 1 :(得分:0)

您可以使用foreach()循环来循环获取对象值,如下所示:

foreach($tweet as $value)
{echo "Screen Name : ".$value->screen_name."<br>";
echo "Tweet : ". $value->text."<br>";
}