Get Original Tweet Username from retweeted_status


#1

Hi,

The code below shows the output from the PHP json_decode function for a JSON response from the GET statuses/user_timeline REST command. In some instances I have found that retweeted text is truncated because it prefixes the text with the username of the original tweet author, thus extending the character count beyond 140 - see line 7 in code.

This can be overcome by using the text property of retweeted_status object which includes the complete original tweet without the username - see line 66 in code. This is fine. However, if I now want to get the original tweet author, there doesn’t appear to be a property within retweeted_status for this. The only option seems to be to use string manipulation on main tweet text property as mentioned above to pull the username out - see line 7 in the code. This is not really a robust solution. Is there a better way of doing this?

Thanks

array (size=10)
  0 => 
    object(stdClass)[36]
      public 'created_at' => string 'Thu Oct 25 10:35:08 +0000 2012' (length=30)
      public 'id' => float 2.6141559068885E+17
      public 'id_str' => string '261415590688854017' (length=18)
      public 'text' => string 'RT @deborahcolson: Systematic review on the use of parachutes to prevent major trauma finds evidence lacking and recommends RCT http://t ...' (length=140)
      public 'source' => string 'web' (length=3)
      public 'truncated' => boolean false
      public 'in_reply_to_status_id' => null
      public 'in_reply_to_status_id_str' => null
      public 'in_reply_to_user_id' => null
      public 'in_reply_to_user_id_str' => null
      public 'in_reply_to_screen_name' => null
      public 'user' => 
        object(stdClass)[37]
          public 'id' => int 297895588
          public 'id_str' => string '297895588' (length=9)
          public 'name' => string 'Caroline Farrell' (length=16)
          public 'screen_name' => string 'essnutrition' (length=12)
          public 'location' => string 'London and Dublin' (length=17)
          public 'description' => string 'Nutritionist with clinics in London, Herts & Dublin. Contributes to Zest, Top Santé, Men’s Health, ivillage & more. www.facebook.com/Essnutrition. ' (length=150)
          public 'url' => string 'http://www.essnutrition.com' (length=27)
          public 'entities' => 
            object(stdClass)[38]
              ...
          public 'protected' => boolean false
          public 'followers_count' => int 262
          public 'friends_count' => int 175
          public 'listed_count' => int 3
          public 'created_at' => string 'Fri May 13 09:29:11 +0000 2011' (length=30)
          public 'favourites_count' => int 1
          public 'utc_offset' => null
          public 'time_zone' => null
          public 'geo_enabled' => boolean false
          public 'verified' => boolean false
          public 'statuses_count' => int 87
          public 'lang' => string 'en' (length=2)
          public 'contributors_enabled' => boolean false
          public 'is_translator' => boolean false
          public 'profile_background_color' => string 'E3E6E1' (length=6)
          public 'profile_background_image_url' => string 'http://a0.twimg.com/profile_background_images/423615382/logo_header_background.png' (length=82)
          public 'profile_background_image_url_https' => string 'https://si0.twimg.com/profile_background_images/423615382/logo_header_background.png' (length=84)
          public 'profile_background_tile' => boolean false
          public 'profile_image_url' => string 'http://a0.twimg.com/profile_images/2449995748/tcew5p8cpkgkrvaw9qlp_normal.png' (length=77)
          public 'profile_image_url_https' => string 'https://si0.twimg.com/profile_images/2449995748/tcew5p8cpkgkrvaw9qlp_normal.png' (length=79)
          public 'profile_link_color' => string '92D050' (length=6)
          public 'profile_sidebar_border_color' => string 'EEEEEE' (length=6)
          public 'profile_sidebar_fill_color' => string 'FFFFFF' (length=6)
          public 'profile_text_color' => string '8ACD43' (length=6)
          public 'profile_use_background_image' => boolean true
          public 'default_profile' => boolean false
          public 'default_profile_image' => boolean false
          public 'following' => boolean false
          public 'follow_request_sent' => boolean false
          public 'notifications' => boolean false
      public 'geo' => null
      public 'coordinates' => null
      public 'place' => null
      public 'contributors' => null
      public 'retweeted_status' => 
        object(stdClass)[42]
          public 'created_at' => string 'Sun Oct 21 07:21:04 +0000 2012' (length=30)
          public 'id' => float 2.5991720235711E+17
          public 'id_str' => string '259917202357108736' (length=18)
          public 'text' => string 'Systematic review on the use of parachutes to prevent major trauma finds evidence lacking and recommends RCT http://t.co/xYIgvqgm' (length=129)
          public 'source' => string 'web' (length=3)
          public 'truncated' => boolean false
          public 'in_reply_to_status_id' => null
          public 'in_reply_to_status_id_str' => null
          public 'in_reply_to_user_id' => null
          public 'in_reply_to_user_id_str' => null
          public 'in_reply_to_screen_name' => null
          public 'user' => 
            object(stdClass)[43]
              ...
          public 'geo' => null
          public 'coordinates' => null
          public 'place' => null
          public 'contributors' => null
          public 'retweet_count' => int 2
          public 'entities' => 
            object(stdClass)[48]
              ...
          public 'favorited' => boolean false
          public 'retweeted' => boolean false
          public 'possibly_sensitive' => boolean false
      public 'retweet_count' => int 2
      public 'entities' => 
        object(stdClass)[50]
          public 'hashtags' => 
            array (size=0)
              ...
          public 'urls' => 
            array (size=0)
              ...
          public 'user_mentions' => 
            array (size=1)
              ...
      public 'favorited' => boolean false
      public 'retweeted' => boolean false

#2

Are you not finding a “user” object in your retweeted_status object? You should find the original author’s user object embedded within the retweeted_status.