2015-02-24 49 views
2

我一直在以JSon格式存儲大量Tweets。現在,我試圖將它們讀回狀態,但對象創建只填充了一些字段,即使原始Json包含所有信息。twitter4j twitterobjectfactory.createstatus將retweetedStatus返回爲空

這裏是原始JSON

{"createdAt":"Aug 5, 2014 4:03:39 PM", 
"id":496733290263760896, 
"text":"RT @lucasfresno: Bora se encacha?ar! RT @zerohora: Leia agora em http://t.co/ho1jjRsIpH http://t.co/VPRDdg35oO", 
"source":"\u003ca href\u003d\"http://twitter.com/download/iphone\" rel\u003d\"nofollow\"\u003eTwitter for iPhone\u003c/a\u003e", 
"isTruncated":false, 
"inReplyToStatusId":-1, 
"inReplyToUserId":-1, 
"isFavorited":false, 
"retweetCount":0, 
"isPossiblySensitive":false, 
"contributorsIDs":[], 
"retweetedStatus":{"createdAt":"Aug 5, 2014 1:39:46 PM", 
        "id":496697079394492417, 
        "text":"Bora se encacha?ar! RT @zerohora: Leia agora em http://t.co/ho1jjRsIpH http://t.co/VPRDdg35oO", 
        "source":"\u003ca href\u003d\"http://twitter.com/download/iphone\" rel\u003d\"nofollow\"\u003eTwitter for iPhone\u003c/a\u003e", 
        "isTruncated":false, 
        "inReplyToStatusId":496694316656381952, 
        "inReplyToUserId":13531162, 
        "isFavorited":false, 
        "inReplyToScreenName":"zerohora", 
        "retweetCount":76, 
        "isPossiblySensitive":false, 
        "contributorsIDs":[], 
        "userMentionEntities":[{"name":"Zero Hora", 
              "screenName":"zerohora", 
              "id":13531162, 
              "start":23, 
              "end":32}], 
        "urlEntities":[{"url":"http://t.co/ho1jjRsIpH", 
            "expandedURL":"http://zh.com.br", 
            "displayURL":"zh.com.br", 
            "start":48, 
            "end":70}], 
        "hashtagEntities":[], 
        "mediaEntities":[{"id":496694316467646464, 
             "url":"http://t.co/VPRDdg35oO", 
             "mediaURL":"http://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg", 
             "mediaURLHttps":"https://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg", 
             "expandedURL":"http://twitter.com/zerohora/status/496694316656381952/photo/1", 
             "displayURL":"pic.twitter.com/VPRDdg35oO", 
             "sizes":{"0":{"width":150,"height":150,"resize":101},"1":{"width":340,"height":375,"resize":100},"2":{"width":477,"height":527,"resize":100},"3":{"width":477,"height":527,"resize":100}}, 
             "type":"photo", 
             "start":71, 
             "end":93}], 
        "currentUserRetweetId":-1, 
        "user":{"id":49315012, 
          "name":"Lucas Silveira", 
          "screenName":"lucasfresno", 
          "location":"Em tudo que ? lugar.", 
          "description":"Fresno, Beeshop, SIRsir, Visconde, Vaconaut \u0026 The Apple Monster, Dark Matter, Poop Straps...", 
          "descriptionURLEntities":[], 
          "isContributorsEnabled":false, 
          "profileImageUrl":"http://pbs.twimg.com/profile_images/378800000615174403/68c2ac7b73415c6e06d71f8330b50d55_normal.jpeg", 
          "profileImageUrlHttps":"https://pbs.twimg.com/profile_images/378800000615174403/68c2ac7b73415c6e06d71f8330b50d55_normal.jpeg", 
          "url":"http://www.fresnorock.com.br", 
          "isProtected":false, 
          "followersCount":883117, 
          "profileBackgroundColor":"FFFFFF", 
          "profileTextColor":"666666", 
          "profileLinkColor":"2FC2EF", 
          "profileSidebarFillColor":"252429", 
          "profileSidebarBorderColor":"181A1E", 
          "profileUseBackgroundImage":true, 
          "showAllInlineMedia":false, 
          "friendsCount":628, 
          "createdAt":"Jun 21, 2009 10:34:03 AM", 
          "favouritesCount":80, 
          "utcOffset":-10800, 
          "timeZone":"Brasilia", 
          "profileBackgroundImageUrl":"http://pbs.twimg.com/profile_background_images/414221729/space.jpg", 
          "profileBackgroundImageUrlHttps":"https://pbs.twimg.com/profile_background_images/414221729/space.jpg", 
          "profileBackgroundTiled":false, 
          "lang":"en", 
          "statusesCount":55070, 
          "isGeoEnabled":true, 
          "isVerified":true, 
          "translator":false, 
          "listedCount":8724, 
          "isFollowRequestSent":false}}, 
"userMentionEntities":[{"name":"Lucas Silveira", 
         "screenName":"lucasfresno", 
         "id":49315012, 
         "start":3, 
         "end":15}, 
         {"name":"Zero Hora", 
         "screenName":"zerohora", 
         "id":13531162, 
         "start":40, 
         "end":49}], 
"urlEntities":[{"url":"http://t.co/ho1jjRsIpH", 
       "expandedURL":"http://zh.com.br", 
       "displayURL":"zh.com.br", 
       "start":65, 
       "end":87}], 
"hashtagEntities":[], 
"mediaEntities":[{"id":496694316467646464, 
        "url":"http://t.co/VPRDdg35oO", 
        "mediaURL":"http://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg", 
        "mediaURLHttps":"https://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg", 
        "expandedURL":"http://twitter.com/zerohora/status/496694316656381952/photo/1", 
        "displayURL":"pic.twitter.com/VPRDdg35oO", 
        "sizes":{"0":{"width":150,"height":150,"resize":101},"1":{"width":340,"height":375,"resize":100},"2":{"width":477,"height":527,"resize":100},"3":{"width":477,"height":527,"resize":100}}, 
        "type":"photo", 
        "start":88, 
        "end":110}], 
"currentUserRetweetId":-1, 
"user":{"id":25413124, 
     "name":"Mariana Mussi", 
     "screenName":"MarianaMussi", 
     "location":"Brazil", 
     "description":"Minky Momo is here...E sigam-me os bons! Ps: Sou um docinho sim, mas ?s vezes posso ser de maracuj? ou lim?o ;) ? http://about.me/mariana.mussi", 
     "descriptionURLEntities":[], 
     "isContributorsEnabled":false, 
     "profileImageUrl":"http://pbs.twimg.com/profile_images/3487510187/6545498cd8cd7605637d9458c4c9e272_normal.jpeg", 
     "profileImageUrlHttps":"https://pbs.twimg.com/profile_images/3487510187/6545498cd8cd7605637d9458c4c9e272_normal.jpeg", 
     "url":"http://www.facebook.com/profile.php?id\u003d1106187557", 
     "isProtected":false, 
     "followersCount":391, 
     "profileBackgroundColor":"FFBDCF", 
     "profileTextColor":"41474D", 
     "profileLinkColor":"4DABC7", 
     "profileSidebarFillColor":"F7FBFC", 
     "profileSidebarBorderColor":"FFFFFF", 
     "profileUseBackgroundImage":true, 
     "showAllInlineMedia":false, 
     "friendsCount":386, 
     "createdAt":"Mar 19, 2009 8:46:35 PM", 
     "favouritesCount":4991, 
     "utcOffset":-10800, 
     "timeZone":"Brasilia", 
     "profileBackgroundImageUrl":"http://pbs.twimg.com/profile_background_images/195172436/minkymomomarianamussibg5.png", 
     "profileBackgroundImageUrlHttps":"https://pbs.twimg.com/profile_background_images/195172436/minkymomomarianamussibg5.png", 
     "profileBannerImageUrl":"https://pbs.twimg.com/profile_banners/25413124/1355939835", 
     "profileBackgroundTiled":true, 
     "lang":"pt", 
     "statusesCount":38951, 
     "isGeoEnabled":true, 
     "isVerified":false, 
     "translator":false, 
     "listedCount":9, 
     "isFollowRequestSent":false} 
} 

這裏是從狀態S = TwitterObjectFactory.createStatus(線)的對象結果;呼叫。

StatusJSONImpl{ 
    createdAt=null, 
    id=496733290263760896, 
    text='RT @lucasfresno: Bora se encacha?ar! RT @zerohora: Leia agora em http://t.co/ho1jjRsIpH http://t.co/VPRDdg35oO', 
    source='<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>', 
    isTruncated=false, 
    inReplyToStatusId=-1, 
    inReplyToUserId=-1, 
    isFavorited=false, 
    isRetweeted=false, 
    favoriteCount=-1, 
    inReplyToScreenName='null', 
    geoLocation=null, 
    place=null, 
    retweetCount=-1, 
    isPossiblySensitive=false, 
    lang='null', 
    contributorsIDs=[], 
    retweetedStatus=null, 
    userMentionEntities=[], 
    urlEntities=[], 
    hashtagEntities=[], 
    mediaEntities=[], 
    symbolEntities=[], 
    currentUserRetweetId=-1, 
    user=UserJSONImpl{ 
     id=25413124, 
     name='Mariana Mussi', 
     screenName='null', 
     location='Brazil', 
     description='Minky Momo is here...E sigam-me os bons! Ps: Sou um docinho sim, mas ?s vezes posso ser de maracuj? ou lim?o ;) ? http://about.me/mariana.mussi', 
     isContributorsEnabled=false, 
     profileImageUrl='null', 
     profileImageUrlHttps='null', 
     isDefaultProfileImage=false, 
     url='http://www.facebook.com/profile.php?id=1106187557', 
     isProtected=false, 
     followersCount=-1, 
     status=null, 
     profileBackgroundColor='null', 
     profileTextColor='null', 
     profileLinkColor='null', 
     profileSidebarFillColor='null', 
     profileSidebarBorderColor='null', 
     profileUseBackgroundImage=false, 
     isDefaultProfile=false, 
     showAllInlineMedia=false, 
     friendsCount=-1, 
     createdAt=null, 
     favouritesCount=-1, 
     utcOffset=-1, 
     timeZone='null', 
     profileBackgroundImageUrl='null', 
     profileBackgroundImageUrlHttps='null', 
     profileBackgroundTiled=false, 
     lang='pt', 
     statusesCount=-1, 
     isGeoEnabled=false, 
     isVerified=false, 
     translator=false, 
     listedCount=-1, 
     isFollowRequestSent=false 
     } 
} 

有沒有人解決過這個問題?我還沒有找到任何地方的實際解決方案。 在此先感謝您的幫助。

編輯:我從GIT下載了源代碼並在本地修復了createStatus方法。儘管如此,似乎這個問題現在應該已經修復,除非有我丟失的東西...

回答

1

問題是,你想完成什麼?
更容易創建一個JSONObject,然後對狀態做任何你想做的事情。 Twitter4j有一個JSONObject接口,或者你可以使用org.json,如果你想,例如,你只需要從你存儲的Json中獲得轉推的狀態。

JSONObject json = new JSONObject(line); 
System.out.println(json.get("retweeted_status")); 

UPDATE
您的原始JSON是錯誤的,你有retweetedStatus而不是retweeted_status作爲RT場,這就是爲什麼你總是讓NULL。一個JSON表格twitter是這樣的

{ 
    "in_reply_to_status_id_str": null, 
    "in_reply_to_status_id": null, 
    "coordinates": null, 
    "created_at": "Wed Oct 22 18:05:19 +0000 2014", 
    "truncated": false, 
    "in_reply_to_user_id_str": null, 
    "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>", 
    "retweeted_status": { 
    "in_reply_to_status_id_str": null, 
    "in_reply_to_status_id": null, 
    "coordinates": null, 
    "created_at": "Wed Oct 22 17:58:08 +0000 2014", 
    "truncated": false, 
    "in_reply_to_user_id_str": null, 
    "source": "<a href=\"http://itunes.apple.com/us/app/twitter/id409789998?mt=12\" rel=\"nofollow\">Twitter for Mac</a>", 
    "retweet_count": 6, 
    "retweeted": false, 
    "geo": null, 
    "in_reply_to_screen_name": null, 
    "entities": { 
     "urls": [], 
     "hashtags": [ 
     { 
      "indices": [ 
      91, 
      101 
      ], 
      "text": "Microsoft" 
     }, 
     { 
      "indices": [ 
      102, 
      110 
      ], 
      "text": "Windows" 
     }, 
     { 
      "indices": [ 
      129, 
      140 
      ], 
      "text": "LeyZamudio" 
     } 
     ], 
     "user_mentions": [ 
     { 
      "indices": [ 
      46, 
      52 
      ], 
      "screen_name": "Corfo", 
      "id_str": "57015564", 
      "name": "Corfo", 
      "id": 57015564 
     } 
     ], 
     "symbols": [] 
    }, 
    "id_str": "524983055652360192", 
    "in_reply_to_user_id": null, 
    "favorite_count": 4, 
    "id": 524983055652360200, 
    "text": "El Chileno tiene derecho a postular a capital @Corfo Pero q NO te dejen postular x NO usar #Microsoft #Windows es Discriminación #LeyZamudio", 
    "place": null, 
    "contributors": null, 
    "lang": "es", 
    "user": { 
     "utc_offset": null, 
     "friends_count": 780, 
     "profile_image_url_https": "https://pbs.twimg.com/profile_images/492125365293568000/qsIuWYjP_normal.jpeg", 
     "listed_count": 34, 
     "profile_background_image_url": "http://abs.twimg.com/images/themes/theme14/bg.gif", 
     "default_profile_image": false, 
     "favourites_count": 135, 
     "description": "Músico & Geek; Marido & Papá. Co-Fundador & Director Ejecutivo de @pantalla_cl; stay hungry, stay foolish (Steve Jobs -June 2005)", 
     "created_at": "Tue Mar 11 12:53:02 +0000 2008", 
     "is_translator": false, 
     "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme14/bg.gif", 
     "protected": false, 
     "screen_name": "andresreitze", 
     "id_str": "14122556", 
     "profile_link_color": "009999", 
     "is_translation_enabled": false, 
     "id": 14122556, 
     "geo_enabled": true, 
     "profile_background_color": "131516", 
     "lang": "es", 
     "profile_sidebar_border_color": "EEEEEE", 
     "profile_location": null, 
     "profile_text_color": "333333", 
     "verified": false, 
     "profile_image_url": "http://pbs.twimg.com/profile_images/492125365293568000/qsIuWYjP_normal.jpeg", 
     "time_zone": null, 
     "url": "http://t.co/IodqmRZoS7", 
     "contributors_enabled": false, 
     "profile_background_tile": true, 
     "profile_banner_url": "https://pbs.twimg.com/profile_banners/14122556/1398980661", 
     "entities": { 
     "description": { 
      "urls": [] 
     }, 
     "url": { 
      "urls": [ 
      { 
       "display_url": "facebook.com/Pantalla.cl", 
       "indices": [ 
       0, 
       22 
       ], 
       "expanded_url": "http://www.facebook.com/Pantalla.cl", 
       "url": "http://t.co/IodqmRZoS7" 
      } 
      ] 
     } 
     }, 
     "statuses_count": 26786, 
     "follow_request_sent": false, 
     "followers_count": 1269, 
     "profile_use_background_image": true, 
     "default_profile": false, 
     "following": false, 
     "name": "Andrés Reitze", 
     "location": "Santiago, Chile", 
     "profile_sidebar_fill_color": "EFEFEF", 
     "notifications": false 
    }, 
    "favorited": false 
    }, 
    "retweet_count": 6, 
    "retweeted": false, 
    "geo": null, 
    "in_reply_to_screen_name": null, 
    "entities": { 
    "urls": [], 
    "hashtags": [ 
     { 
     "indices": [ 
      109, 
      119 
     ], 
     "text": "Microsoft" 
     }, 
     { 
     "indices": [ 
      120, 
      128 
     ], 
     "text": "Windows" 
     }, 
     { 
     "indices": [ 
      139, 
      140 
     ], 
     "text": "LeyZamudio" 
     } 
    ], 
    "user_mentions": [ 
     { 
     "indices": [ 
      3, 
      16 
     ], 
     "screen_name": "andresreitze", 
     "id_str": "14122556", 
     "name": "Andrés Reitze", 
     "id": 14122556 
     }, 
     { 
     "indices": [ 
      64, 
      70 
     ], 
     "screen_name": "Corfo", 
     "id_str": "57015564", 
     "name": "Corfo", 
     "id": 57015564 
     } 
    ], 
    "symbols": [] 
    }, 
    "id_str": "524984861342564352", 
    "in_reply_to_user_id": null, 
    "favorite_count": 0, 
    "id": 524984861342564350, 
    "text": "RT @andresreitze: El Chileno tiene derecho a postular a capital @Corfo Pero q NO te dejen postular x NO usar #Microsoft #Windows es Discrim…", 
    "place": null, 
    "contributors": null, 
    "lang": "es", 
    "user": { 
    "utc_offset": -10800, 
    "friends_count": 1419, 
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/458940469443952641/k4W4RMkF_normal.jpeg", 
    "listed_count": 5, 
    "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/83201515/TWITTER.jpg", 
    "default_profile_image": false, 
    "favourites_count": 7, 
    "description": "", 
    "created_at": "Thu Jan 21 20:37:37 +0000 2010", 
    "is_translator": false, 
    "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/83201515/TWITTER.jpg", 
    "protected": false, 
    "screen_name": "estebanmmp", 
    "id_str": "107197310", 
    "profile_link_color": "009999", 
    "is_translation_enabled": false, 
    "id": 107197310, 
    "geo_enabled": true, 
    "profile_background_color": "131516", 
    "lang": "es", 
    "profile_sidebar_border_color": "EEEEEE", 
    "profile_location": null, 
    "profile_text_color": "333333", 
    "verified": false, 
    "profile_image_url": "http://pbs.twimg.com/profile_images/458940469443952641/k4W4RMkF_normal.jpeg", 
    "time_zone": "Santiago", 
    "url": null, 
    "contributors_enabled": false, 
    "profile_background_tile": false, 
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/107197310/1398254745", 
    "entities": { 
     "description": { 
     "urls": [] 
     } 
    }, 
    "statuses_count": 2354, 
    "follow_request_sent": false, 
    "followers_count": 390, 
    "profile_use_background_image": true, 
    "default_profile": false, 
    "following": false, 
    "name": "ESTEBAN MMP", 
    "location": "viña del mar, chile", 
    "profile_sidebar_fill_color": "EFEFEF", 
    "notifications": false 
    }, 
    "favorited": false 
} 

你是如何存儲你的數據?您需要撥打TwitterObjectFactory.getRawJSON(status)以獲取原始JSON。可能你沒有這樣做,這就是爲什麼twitterobjectfactory.createstatus返回retweettedStatus總是爲空。

+0

問題是我有超過50個功能,我以前爲使用實時數據的項目構建並期望有一個Status對象。我把它們變成了一個圖書館,我希望在這個新項目中使用它們。 我同意JSON會提供這些信息,但是維護該代碼需要比修復Twitter4J庫更多的時間。 – maiona 2015-02-26 15:47:36

+0

你原來的JSON是錯誤的,你已經retweetedStatus而不是retweeted_status作爲RT域): – FeanDoe 2015-02-26 16:11:05

+0

感謝您的幫助,FeanDoe!這回答了我的問題。 – maiona 2015-02-27 17:01:01