Php Json get first element info -
so i'm using php twitter api grab list of tweets hashtag. i'm looking following info returned json; 'screen_name' , 'text'.
the screen_name on line 44 , text on line 20.
here json output.
object(stdclass)#5 (2) { ["statuses"]=> array(15) { [0]=> object(stdclass)#6 (24) { ["metadata"]=> object(stdclass)#7 (2) { ["iso_language_code"]=> string(2) "en" ["result_type"]=> string(6) "recent" } ["created_at"]=> string(30) "fri dec 05 21:22:00 +0000 2014" ["id"]=> float(5.4097942452372e+17) ["id_str"]=> string(18) "540979424523718656" ["text"]=> string(100) "shits getting real. crit happens tonight. #dnd #dungeonsanddragons #nerd #rpg http://t.co/44lnrmmfte" ["source"]=> string(59) "<a href="http://instagram.com" rel="nofollow">instagram</a>" ["truncated"]=> bool(false) ["in_reply_to_status_id"]=> null ["in_reply_to_status_id_str"]=> null ["in_reply_to_user_id"]=> null ["in_reply_to_user_id_str"]=> null ["in_reply_to_screen_name"]=> null ["user"]=> object(stdclass)#8 (41) { ["id"]=> int(1297196190) ["id_str"]=> string(10) "1297196190" ["name"]=> string(12) "brandon wade" ["screen_name"]=> string(15) "brandonus_prime" ["location"]=> string(15) "the woods of nc" ["profile_location"]=> null ["description"]=> string(29) "if bleeds, can kill it." ["url"]=> string(22) "http://t.co/ekgudm9ydo" ["entities"]=> object(stdclass)#9 (2) { ["url"]=> object(stdclass)#10 (1) { ["urls"]=> array(1) { [0]=> object(stdclass)#11 (4) { ["url"]=> string(22) "http://t.co/ekgudm9ydo" ["expanded_url"]=> string(34) "http://facebook.com/brandonusprime" ["display_url"]=> string(27) "facebook.com/brandonusprime" ["indices"]=> array(2) { [0]=> int(0) [1]=> int(22) } } } } ["description"]=> object(stdclass)#12 (1) { ["urls"]=> array(0) { } } } ["protected"]=> bool(false) ["followers_count"]=> int(44) ["friends_count"]=> int(246) ["listed_count"]=> int(0) ["created_at"]=> string(30) "mon mar 25 01:10:47 +0000 2013" ["favourites_count"]=> int(18) ["utc_offset"]=> null ["time_zone"]=> null ["geo_enabled"]=> bool(false) ["verified"]=> bool(false) ["statuses_count"]=> int(170) ["lang"]=> string(2) "en" ["contributors_enabled"]=> bool(false) ["is_translator"]=> bool(false) ["is_translation_enabled"]=> bool(false) ["profile_background_color"]=> string(6) "c0deed" ["profile_background_image_url"]=> string(48) "http://abs.twimg.com/images/themes/theme1/bg.png" ["profile_background_image_url_https"]=> string(49) "https://abs.twimg.com/images/themes/theme1/bg.png" ["profile_background_tile"]=> bool(false) ["profile_image_url"]=> string(99) "http://pbs.twimg.com/profile_images/378800000698263057/6592d36cf8e2beb02c9f3ee9abf4fdd7_normal.jpeg" ["profile_image_url_https"]=> string(100) "https://pbs.twimg.com/profile_images/378800000698263057/6592d36cf8e2beb02c9f3ee9abf4fdd7_normal.jpeg" ["profile_banner_url"]=> string(59) "https://pbs.twimg.com/profile_banners/1297196190/1364236862" ["profile_link_color"]=> string(6) "0084b4" ["profile_sidebar_border_color"]=> string(6) "c0deed" ["profile_sidebar_fill_color"]=> string(6) "ddeef6" ["profile_text_color"]=> string(6) "333333" ["profile_use_background_image"]=> bool(true) ["default_profile"]=> bool(true) ["default_profile_image"]=> bool(false) ["following"]=> bool(false) ["follow_request_sent"]=> bool(false) ["notifications"]=> bool(false) } ["geo"]=> null ["coordinates"]=> null ["place"]=> null ["contributors"]=> null ["retweet_count"]=> int(0) ["favorite_count"]=> int(0) ["entities"]=> object(stdclass)#13 (4) { ["hashtags"]=> array(4) { [0]=> object(stdclass)#14 (2) { ["text"]=> string(3) "dnd" ["indices"]=> array(2) { [0]=> int(42) [1]=> int(46) } } [1]=> object(stdclass)#15 (2) { ["text"]=> string(18) "dungeonsanddragons" ["indices"]=> array(2) { [0]=> int(47) [1]=> int(66) } } [2]=> object(stdclass)#16 (2) { ["text"]=> string(4) "nerd" ["indices"]=> array(2) { [0]=> int(67) [1]=> int(72) } } [3]=> object(stdclass)#17 (2) { ["text"]=> string(3) "rpg" ["indices"]=> array(2) { [0]=> int(73) [1]=> int(77) } } } ["symbols"]=> array(0) { } ["user_mentions"]=> array(0) { } ["urls"]=> array(1) { [0]=> object(stdclass)#18 (4) { ["url"]=> string(22) "http://t.co/44lnrmmfte" ["expanded_url"]=> string(34) "http://instagram.com/p/wpv3gmr1kl/" ["display_url"]=> string(27) "instagram.com/p/wpv3gmr1kl/" ["indices"]=> array(2) { [0]=> int(78) [1]=> int(100) } } } } ["favorited"]=> bool(false) ["retweeted"]=> bool(false) ["possibly_sensitive"]=> bool(false) ["lang"]=> string(2) "en" } }
here php code
<?php require_once 'twitteroauth/twitteroauth.php'; define('consumer_key', ''); define('consumer_secret', ''); define('access_token', '-'); define('access_token_secret', ''); $toa = new twitteroauth(consumer_key, consumer_secret, access_token, access_token_secret); $query = array( "q" => "#nerd", "result_type" => "recent" ); $results = $toa->get('search/tweets', $query); var_dump($results); die(); foreach ($results->statuses $result) { echo $result->user->screen_name . ": " . $result->text . "<br>"; }
thanks ton! i've been trying while , need pointing in right direction :)
Comments
Post a Comment