-6

From the following response from Twitter, how can I access 'followers_count'?

array(1) { 
    [0]=> object(stdClass)#1 (21) { 
        ["created_at"]=> string(30) "Mon Oct 15   19:20:28 +0000 2012" 
        ["id"]=> int(257923917879070721) 
        ["id_str"]=> string(18) "257923917879070721" 
        ["text"]=> string(127) "As open enrollment begins, Medicare is getting stronger – but Rep. Ryan wants to dismantle it. My op-ed: http://t.co/DUEYxQOt"  
        ["source"]=> string(3) "web"  
        ["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)#2 (38) {  
            ["id"]=> int(16789970)  
            ["id_str"]=> string(8) "16789970"  
            ["name"]=> string(18) "Senator Harry Reid"  
            ["screen_name"]=> string(11) "SenatorReid"  
            ["location"]=> string(15) "Searchlight, NV"  
            ["url"]=> string(22) "http://reid.senate.gov"  
            ["description"]=> string(108) "News from the office of Nevada Senator Harry Reid, the U.S. Senate Majority Leader. (Español: @SenadorReid)"  
            ["protected"]=> bool(false)  
            ["followers_count"]=> int(67261)  
            ["friends_count"]=> int(126)  
            ["listed_count"]=> int(3712)  
            ["created_at"]=> string(30) "Wed Oct 15 19:42:08 +0000 2008"  
            ["favourites_count"]=> int(1)  
            ["utc_offset"]=> int(-18000)  
            ["time_zone"]=> string(5) "Quito"  
            ["geo_enabled"]=> bool(false)  
            ["verified"]=> bool(true)  
            ["statuses_count"]=> int(1556)  
            ["lang"]=> string(2) "en"  
            ["contributors_enabled"]=> bool(false)  
            ["is_translator"]=> bool(false)  
            ["profile_background_color"]=> string(6) "233E6D"  
            ["profile_background_image_url"]=> string(70) "http://a0.twimg.com/profile_background_images/4744650/reid_twitter.jpg"  
            ["profile_background_image_url_https"]=> string(72) "https://si0.twimg.com/profile_background_images/4744650/reid_twitter.jpg"  
            ["profile_background_tile"]=> bool(false)  
            ["profile_image_url"]=> string(66) "http://a0.twimg.com/profile_images/81906216/reid_square_normal.jpg"  
            ["profile_image_url_https"]=> string(68) "https://si0.twimg.com/profile_images/81906216/reid_square_normal.jpg"  
            ["profile_banner_url"]=> string(63) "https://si0.twimg.com/brand_banners/SenatorReid/1323385337/live"  
            ["profile_link_color"]=> string(6) "004CB4"  
            ["profile_sidebar_border_color"]=> string(6) "6383A3"  
            ["profile_sidebar_fill_color"]=> string(6) "AFC4DA"  
            ["profile_text_color"]=> string(6) "333333"  
            ["profile_use_background_image"]=> bool(true)  
            ["default_profile"]=> bool(false)  
            ["default_profile_image"]=> bool(false)  
            ["following"]=> NULL  
            ["follow_request_sent"]=> NULL  
            ["notifications"]=> NULL } ["geo"]=> NULL  
            ["coordinates"]=> NULL  
            ["place"]=> NULL  
            ["contributors"]=> NULL  
            ["retweet_count"]=> int(88)  
            ["entities"]=> object(stdClass)#3 (3) {  
                ["hashtags"]=> array(0) { }  
                ["urls"]=> array(1) {  
                    [0]=> object(stdClass)#4 (4) {  
                        ["url"]=> string(20) "http://t.co/DUEYxQOt"  
                        ["expanded_url"]=> string(21) "http://huff.to/TshePO"  
                        ["display_url"]=> string(14) "huff.to/TshePO"  
                        ["indices"]=> array(2) {  
                            [0]=> int(105)  
                            [1]=> int(125) 
                        } 
                } 
            } 
            ["user_mentions"]=> array(0) { } 
        } 
        ["favorited"]=> bool(false) 
        ["retweeted"]=> bool(false) 
        ["possibly_sensitive"]=> bool(false) 
    } 
}
afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
  • 2
    What's the problem? You already have the object. What are you trying to do? – Saul Martínez Oct 18 '12 at 14:56
  • 1
    possible duplicate of [Able to see a variable in print\_r()'s output, but not sure how to access it in code](http://stackoverflow.com/questions/6322084/able-to-see-a-variable-in-print-rs-output-but-not-sure-how-to-access-it-in-c) - Welcome to Stackoverflow. Please follow the [ask advice](http://stackoverflow.com/questions/ask-advice) you needed to confirm before posting *any* question. Keep in mind that only you want something and you ask yourself how it is programmed does not qualify as a programming question per-se. – hakre Oct 18 '12 at 14:56
  • please be specific what you want to do – Techie Oct 18 '12 at 15:01

2 Answers2

3

To read easly your var_dump, you can install x-debug : http://xdebug.org/.

And to access at your information, it's :

$followersCount = $twitterResponse[0]->user->followers_count

for your example.

jadoux
  • 85
  • 7
  • Unfortunately, that generates the following error: Fatal error: Cannot use object of type stdClass as array in /home/fpadmin/public_html/feedservice/newTwitterFeed.php – user1756685 Oct 18 '12 at 15:18
  • Never mind; I exceeded the rate limit, so there isn't an array returned... – user1756685 Oct 18 '12 at 15:21
0
$response[0]["user"]["followers_count"]
Marco Gagliardi
  • 565
  • 1
  • 8
  • 24