本文整理汇总了Java中twitter4j.json.DataObjectFactory.createStatus方法的典型用法代码示例。如果您正苦于以下问题:Java DataObjectFactory.createStatus方法的具体用法?Java DataObjectFactory.createStatus怎么用?Java DataObjectFactory.createStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter4j.json.DataObjectFactory
的用法示例。
在下文中一共展示了DataObjectFactory.createStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimeRange
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public static Pair<Date, Date> getTimeRange(String hostname, String dbName, String collection) {
Date first = null, last = null;
DBCollection coll = getCollection(hostname, dbName, collection);
DBCursor c = coll.find();
while(c.hasNext()) {
DBObject obj = c.next();
String rawJSON = obj.toString();
try {
Status status = DataObjectFactory.createStatus(rawJSON);
Date d = status.getCreatedAt();
if(first == null || first.after(d))
first = d;
if(last == null || last.before(d))
last = d;
} catch (TwitterException e) { }
}
System.out.println("First tweet at: " + first);
System.out.println("Last tweet at: " + last);
return Pair.of(first, last);
}
示例2: process
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
@Override
public void process(Visibility visibility, StreamEvent streamEvent) {
try {
Status status = DataObjectFactory.createStatus(new String(streamEvent.getContent(), "UTF-8"));
Tweet tweet = this.convertToTweet(status);
String raw = streamEvent.getContent().toString();
TweetWithRaw thriftAndRaw = new TweetWithRaw(tweet, raw);
outputToPipes(visibility, thriftAndRaw);
} catch (TwitterException | IOException e) {
logger.error("Error during tweet output to pipes", streamEvent, e);
AdditionalMetadata metaData = new AdditionalMetadata();
MetadataEntry stackTraceEntry = new MetadataEntry();
stackTraceEntry.setValue(StackTraceUtil.getStackTrace(e));
metaData.putToEntries("stackTrace", stackTraceEntry);
try {
sendObjectToQuarantine(
streamEvent, visibility, "Error during tweet output to pipes", metaData);
} catch (IOException ioe) {
logger.error("FATAL, cannot send object to Quarantine.", ioe);
throw new RuntimeException("Could not send object to Quarantine.", ioe);
}
}
}
示例3: main
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
/**
* Usage: java twitter4j.examples.json.LoadRawJSON
*
* @param args String[]
*/
public static void main(String[] args) {
try {
File[] files = new File("statuses").listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".json");
}
});
for (File file : files) {
String rawJSON = readFirstLine(file);
Status status = DataObjectFactory.createStatus(rawJSON);
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}
System.exit(0);
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Failed to store tweets: " + ioe.getMessage());
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get timeline: " + te.getMessage());
System.exit(-1);
}
}
示例4: testShowStatus
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void testShowStatus() throws Exception {
Status status;
status = DataObjectFactory.createStatus("{\"text\":\"\\\\u5e30%u5e30 <%\\u007d& foobar <&Cynthia>\",\"contributors\":null,\"geo\":null,\"retweeted\":false,\"in_reply_to_screen_name\":null,\"truncated\":false,\"entities\":{\"urls\":[],\"hashtags\":[],\"user_mentions\":[]},\"in_reply_to_status_id_str\":null,\"id\":12029015787307008,\"in_reply_to_user_id_str\":null,\"source\":\"web\",\"favorited\":false,\"in_reply_to_status_id\":null,\"in_reply_to_user_id\":null,\"created_at\":\"Tue Dec 07 06:21:55 +0000 2010\",\"retweet_count\":0,\"id_str\":\"12029015787307008\",\"place\":null,\"user\":{\"location\":\"location:\",\"statuses_count\":13405,\"profile_background_tile\":false,\"lang\":\"en\",\"profile_link_color\":\"0000ff\",\"id\":6358482,\"following\":true,\"favourites_count\":2,\"protected\":false,\"profile_text_color\":\"000000\",\"contributors_enabled\":false,\"description\":\"Hi there, I do test a lot!new\",\"verified\":false,\"profile_sidebar_border_color\":\"87bc44\",\"name\":\"twit4j\",\"profile_background_color\":\"9ae4e8\",\"created_at\":\"Sun May 27 09:52:09 +0000 2007\",\"followers_count\":24,\"geo_enabled\":true,\"profile_background_image_url\":\"http://a3.twimg.com/profile_background_images/179009017/t4j-reverse.gif\",\"follow_request_sent\":false,\"url\":\"http://yusuke.homeip.net/twitter4j/\",\"utc_offset\":-32400,\"time_zone\":\"Alaska\",\"notifications\":false,\"friends_count\":4,\"profile_use_background_image\":true,\"profile_sidebar_fill_color\":\"e0ff92\",\"screen_name\":\"twit4j\",\"id_str\":\"6358482\",\"profile_image_url\":\"http://a3.twimg.com/profile_images/1184543043/t4j-reverse_normal.jpeg\",\"show_all_inline_media\":false,\"listed_count\":3},\"coordinates\":null}");
assertEquals("\\u5e30%u5e30 <%}& foobar <&Cynthia>", status.getText());
status = twitter2.showStatus(1000l);
assertNotNull(DataObjectFactory.getRawJSON(status));
assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status)));
assertEquals("en", status.getIsoLanguageCode());
assertEquals(52, status.getUser().getId());
Status status2 = twitter1.showStatus(1000l);
assertEquals(52, status2.getUser().getId());
assertNotNull(status.getRateLimitStatus());
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
status2 = twitter1.showStatus(999383469l);
assertEquals("et", status2.getIsoLanguageCode());
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
assertEquals("01010100 01110010 01101001 01110101 01101101 01110000 01101000 <3", status2.getText());
status2 = twitter1.showStatus(12029015787307008l);
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
assertEquals("\\u5e30%u5e30 <%}& foobar <&Cynthia>", status2.getText());
}
示例5: testShowStatus
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void testShowStatus() throws Exception {
Status status;
status = DataObjectFactory.createStatus("{\"text\":\"\\\\u5e30%u5e30 <%\\u007d& foobar <&Cynthia>\",\"contributors\":null,\"geo\":null,\"retweeted\":false,\"in_reply_to_screen_name\":null,\"truncated\":false,\"entities\":{\"urls\":[],\"hashtags\":[],\"user_mentions\":[]},\"in_reply_to_status_id_str\":null,\"id\":12029015787307008,\"in_reply_to_user_id_str\":null,\"source\":\"web\",\"favorited\":false,\"in_reply_to_status_id\":null,\"in_reply_to_user_id\":null,\"created_at\":\"Tue Dec 07 06:21:55 +0000 2010\",\"retweet_count\":0,\"id_str\":\"12029015787307008\",\"place\":null,\"user\":{\"location\":\"location:\",\"statuses_count\":13405,\"profile_background_tile\":false,\"lang\":\"en\",\"profile_link_color\":\"0000ff\",\"id\":6358482,\"following\":true,\"favourites_count\":2,\"protected\":false,\"profile_text_color\":\"000000\",\"contributors_enabled\":false,\"description\":\"Hi there, I do test a lot!new\",\"verified\":false,\"profile_sidebar_border_color\":\"87bc44\",\"name\":\"twit4j\",\"profile_background_color\":\"9ae4e8\",\"created_at\":\"Sun May 27 09:52:09 +0000 2007\",\"followers_count\":24,\"geo_enabled\":true,\"profile_background_image_url\":\"http://a3.twimg.com/profile_background_images/179009017/t4j-reverse.gif\",\"follow_request_sent\":false,\"url\":\"http://yusuke.homeip.net/twitter4j/\",\"utc_offset\":-32400,\"time_zone\":\"Alaska\",\"notifications\":false,\"friends_count\":4,\"profile_use_background_image\":true,\"profile_sidebar_fill_color\":\"e0ff92\",\"screen_name\":\"twit4j\",\"id_str\":\"6358482\",\"profile_image_url\":\"http://a3.twimg.com/profile_images/1184543043/t4j-reverse_normal.jpeg\",\"show_all_inline_media\":false,\"listed_count\":3},\"coordinates\":null}");
assertEquals("\\u5e30%u5e30 <%}& foobar <&Cynthia>", status.getText());
status = twitter2.showStatus(1000l);
assertNotNull(DataObjectFactory.getRawJSON(status));
assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status)));
assertEquals(52, status.getUser().getId());
Status status2 = twitter1.showStatus(1000l);
assertEquals(52, status2.getUser().getId());
assertNotNull(status.getRateLimitStatus());
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
status2 = twitter1.showStatus(999383469l);
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
assertEquals("01010100 01110010 01101001 01110101 01101101 01110000 01101000 <3", status2.getText());
status2 = twitter1.showStatus(12029015787307008l);
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
assertEquals("\\u5e30%u5e30 <%}& foobar <&Cynthia>", status2.getText());
}
示例6: extractSubsetOfTweetFields
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public static void extractSubsetOfTweetFields(List<String> jsonFiles, String outputFile,
StatusTransformer transformer, StatusFilterer filterer) throws IOException, TwitterException {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile), FileUtil.UTF8));
for (int i = 0; i < jsonFiles.size(); i++) {
System.out.println(jsonFiles.get(i));
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(jsonFiles.get(i)), FileUtil.UTF8));
String line = null;
while ((line = reader.readLine())!= null){
Status status = DataObjectFactory.createStatus(line);
if (filterer.acceptStatus(status)){
writer.append(transformer.extractLine(status));
writer.newLine();
}
}
reader.close();
writer.flush();
}
writer.close();
}
示例7: execute
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
Status s = null;
String tweetText = null;
try {
s = DataObjectFactory.createStatus((String) tuple.getValue(0));
tweetText = tools.removeLinksAndReplies(tb.removeSpacesInBetween(s.getText()));
} catch (Exception e) {
LOG.error(e.toString());
}
Tweet t = null;
if (s!=null) //rarely Twitter4J can't parse the json to convert to Status and Status is null.
t = new Tweet(s.getId(), tweetText);
else
t = new Tweet(-1, " ");
collector.emit(new Values(t));
}
示例8: getStatusTweet
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public static Status getStatusTweet(String JSONString){
if (JSONString == null)
return null;
Status tweet = null;
try {
// parse json to object type
tweet = DataObjectFactory.createStatus(JSONString);
} catch (TwitterException e) {
System.err.println("error parsing tweet object");
return null;
}
return tweet;
}
示例9: onStatus
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void onStatus(Status status) {
this.status = status;
String json = DataObjectFactory.getRawJSON(status);
try {
assertNotNull(json);
Status statusFromJSON = DataObjectFactory.createStatus(json);
assertEquals(status, statusFromJSON);
} catch (TwitterException e) {
e.printStackTrace();
}
// System.out.println("got status from stream:" + status.toString());
assertNotNull(status.getText());
// System.out.println(status.getCreatedAt() + ":" + status.getText() + " from:" + status.getSource());
notifyResponse();
}
示例10: testDisplayURLNullCase
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void testDisplayURLNullCase() throws Exception {
// http://jira.twitter4j.org/browse/TFJ-704
// https://gist.github.com/4071950#file_2.parse_error_json_example.txt
// sometimes display_url is null and display_url doesn't exist
String rawJSON = "{ \"geo\": null, \"in_reply_to_screen_name\": null, \"favorited\": false, \"text\": \"RT @fxThailandfans: RT @princezephyr: [PRESS PICS] 121114 f(x) - KOR-AUS Football Match Half-time Show http:\\/\\/t.co\\/cbm1aPCU http:\\/\\/t.co\\/ ...\", \"possibly_sensitive\": false, \"in_reply_to_status_id_str\": null, \"created_at\": \"Wed Nov 14 12:03:02 +0000 2012\", \"in_reply_to_user_id_str\": null, \"retweet_count\": 2, \"coordinates\": null, \"source\": \"<a href=\\\"http:\\/\\/blackberry.com\\/twitter\\\" rel=\\\"nofollow\\\">Twitter for BlackBerry\\u00ae<\\/a>\", \"entities\": { \"hashtags\": [ ], \"user_mentions\": [ { \"indices\": [ 3, 18 ], \"screen_name\": \"fxThailandfans\", \"id_str\": \"563934022\", \"name\": \"fx_thailand\", \"id\": 563934022 }, { \"indices\": [ 23, 36 ], \"screen_name\": \"princezephyr\", \"id_str\": \"251443396\", \"name\": \"princezephyr\", \"id\": 251443396 } ], \"urls\": [ { \"indices\": [ 103, 123 ], \"display_url\": \"twitpic.com\\/bd46lk\", \"url\": \"http:\\/\\/t.co\\/cbm1aPCU\", \"expanded_url\": \"http:\\/\\/twitpic.com\\/bd46lk\" }, { \"indices\": [ 124, 136 ], \"url\": \"http:\\/\\/t.co\\/\", \"expanded_url\": null } ] }, \"place\": null, \"retweeted\": false, \"truncated\": false, \"id_str\": \"268685470089764864\", \"retweeted_status\": { \"geo\": null, \"in_reply_to_screen_name\": null, \"favorited\": false, \"text\": \"RT @princezephyr: [PRESS PICS] 121114 f(x) - KOR-AUS Football Match Half-time Show http:\\/\\/t.co\\/cbm1aPCU http:\\/\\/t.co\\/UW5HBXHn (7)\", \"possibly_sensitive\": false, \"in_reply_to_status_id_str\": null, \"created_at\": \"Wed Nov 14 11:42:13 +0000 2012\", \"in_reply_to_user_id_str\": null, \"retweet_count\": 2, \"coordinates\": null, \"source\": \"<a href=\\\"http:\\/\\/www.tweetdeck.com\\\" rel=\\\"nofollow\\\">TweetDeck<\\/a>\", \"entities\": { \"hashtags\": [ ], \"user_mentions\": [ { \"indices\": [ 3, 16 ], \"screen_name\": \"princezephyr\", \"id_str\": \"251443396\", \"name\": \"princezephyr\", \"id\": 251443396 } ], \"urls\": [ { \"indices\": [ 83, 103 ], \"display_url\": \"twitpic.com\\/bd46lk\", \"url\": \"http:\\/\\/t.co\\/cbm1aPCU\", \"expanded_url\": \"http:\\/\\/twitpic.com\\/bd46lk\" }, { \"indices\": [ 104, 124 ], \"display_url\": \"twitpic.com\\/bd46tf\", \"url\": \"http:\\/\\/t.co\\/UW5HBXHn\", \"expanded_url\": \"http:\\/\\/twitpic.com\\/bd46tf\" } ] }, \"place\": null, \"retweeted\": false, \"truncated\": false, \"id_str\": \"268680229562744832\", \"contributors\": null, \"in_reply_to_user_id\": null, \"in_reply_to_status_id\": null, \"user\": { \"friends_count\": 44, \"profile_link_color\": \"939AED\", \"followers_count\": 834, \"is_translator\": false, \"default_profile\": false, \"follow_request_sent\": null, \"contributors_enabled\": false, \"time_zone\": \"Bangkok\", \"created_at\": \"Thu Apr 26 18:22:34 +0000 2012\", \"profile_background_color\": \"C0DEED\", \"profile_background_tile\": true, \"profile_background_image_url_https\": \"https:\\/\\/si0.twimg.com\\/profile_background_images\\/576266919\\/0bvixbmvg2lj69ajtg6i.jpeg\", \"url\": \"http:\\/\\/www.fxthailand.com\\/\", \"description\": \"f(x) Thailand Fans Board.\\r\\n\\r\\nhttps:\\/\\/www.facebook.com\\/Fxthailandfans\", \"profile_sidebar_fill_color\": \"DDEEF6\", \"default_profile_image\": false, \"lang\": \"en\", \"favourites_count\": 1, \"profile_sidebar_border_color\": \"C0DEED\", \"profile_image_url_https\": \"https:\\/\\/si0.twimg.com\\/profile_images\\/2592067376\\/3q4797y4mhfcvh7b7k14_normal.png\", \"location\": \"\", \"id_str\": \"563934022\", \"verified\": false, \"notifications\": null, \"protected\": false, \"screen_name\": \"fxThailandfans\", \"following\": null, \"geo_enabled\": false, \"profile_use_background_image\": true, \"profile_image_url\": \"http:\\/\\/a0.twimg.com\\/profile_images\\/2592067376\\/3q4797y4mhfcvh7b7k14_normal.png\", \"name\": \"fx_thailand\", \"profile_text_color\": \"333333\", \"id\": 563934022, \"listed_count\": 6, \"statuses_count\": 1840, \"profile_background_image_url\": \"http:\\/\\/a0.twimg.com\\/profile_background_images\\/576266919\\/0bvixbmvg2lj69ajtg6i.jpeg\", \"utc_offset\": 25200 }, \"id\": 268680229562744832, \"possibly_sensitive_editable\": true }, \"contributors\": null, \"in_reply_to_user_id\": null, \"in_reply_to_status_id\": null, \"user\": { \"friends_count\": 96, \"profile_link_color\": \"0084B4\", \"followers_count\": 62, \"is_translator\": false, \"default_profile\": true, \"follow_request_sent\": null, \"contributors_enabled\": false, \"time_zone\": null, \"created_at\": \"Tue Jul 17 12:29:08 +0000 2012\", \"profile_background_color\": \"C0DEED\", \"profile_background_tile\": false, \"profile_background_image_url_https\": \"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\", \"url\": null, \"description\": \"\\u0e2d\\u0e31\\u0e19\\u0e22\\u0e2d\\u0e07\\u0e04\\u0e48\\u0e30 !! \\u0e09\\u0e31\\u0e19\\u0e0b\\u0e39\\u0e08\\u0e35\\u0e27\\u0e07\\u0e21\\u0e34\\u0e2a\\u0e40\\u0e2d \\u0e09\\u0e31\\u0e19\\u0e23\\u0e31\\u0e48\\u0e27 \\u0e19\\u0e48\\u0e32\\u0e23\\u0e31\\u0e01 \\u0e25\\u0e2d\\u0e07\\u0e1f\\u0e2d\\u0e25\\u0e21\\u0e32\\u0e2a\\u0e34\\u0e04\\u0e48\\u0e30\\u0e41\\u0e25\\u0e49\\u0e27\\u0e04\\u0e38\\u0e13\\u0e08\\u0e30\\u0e23\\u0e39\\u0e49 *\\u0e22\\u0e34\\u0e49\\u0e21\\u0e2a\\u0e27\\u0e22*\", \"profile_sidebar_fill_color\": \"DDEEF6\", \"default_profile_image\": false, \"lang\": \"th\", \"favourites_count\": 2, \"profile_sidebar_border_color\": \"C0DEED\", \"profile_image_url_https\": \"https:\\/\\/si0.twimg.com\\/profile_images\\/2748527294\\/6cd82d00840820ddc2bedffdfb5e15bd_normal.jpeg\", \"location\": \"\\u0e43\\u0e19\\u0e04\\u0e48\\u0e32\\u0e22 JYP \\u0e04\\u0e48\\u0e30\", \"id_str\": \"700968576\", \"verified\": false, \"notifications\": null, \"protected\": false, \"screen_name\": \"suzy12missA\", \"following\": null, \"geo_enabled\": false, \"profile_use_background_image\": true, \"profile_image_url\": \"http:\\/\\/a0.twimg.com\\/profile_images\\/2748527294\\/6cd82d00840820ddc2bedffdfb5e15bd_normal.jpeg\", \"name\": \"\\u0e19\\u0e32\\u0e07\\u0e40\\u0e1a!!\\u0e0b\\u0e39\\u0e08\\u0e35^^\", \"profile_text_color\": \"333333\", \"id\": 700968576, \"listed_count\": 1, \"statuses_count\": 428, \"profile_background_image_url\": \"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\", \"utc_offset\": null }, \"id\": 268680229562744832, \"possibly_sensitive_editable\": true}";
Status status = DataObjectFactory.createStatus(rawJSON);
URLEntity urlEntity = status.getURLEntities()[1];
assertEquals(urlEntity.getURL(), urlEntity.getDisplayURL());
assertEquals(urlEntity.getURL(), urlEntity.getExpandedURL());
}
示例11: testGetIsoLanguageCode
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void testGetIsoLanguageCode() throws Exception {
// given
String json = "{\"contributors\":null,\"text\":\"@belbeer After four years of study in radiotechnical college I realized that the language skills are much more useful than fucking math.\",\"geo\":null,\"retweeted\":false,\"in_reply_to_screen_name\":\"belbeer\",\"truncated\":false,\"entities\":{\"urls\":[],\"hashtags\":[],\"user_mentions\":[{\"id\":74987101,\"name\":\"belbeer\",\"indices\":[0,8],\"screen_name\":\"belbeer\",\"id_str\":\"74987101\"}]},\"in_reply_to_status_id_str\":\"297250346298904576\",\"id\":297265580690513920,\"source\":\"web\",\"in_reply_to_user_id_str\":\"74987101\",\"favorited\":false,\"in_reply_to_status_id\":297250346298904576,\"retweet_count\":0,\"created_at\":\"Fri Feb 01 08:50:12 +0000 2013\",\"in_reply_to_user_id\":74987101,\"id_str\":\"297265580690513920\",\"place\":null,\"user\":{\"location\":\"where am i?\",\"default_profile\":true,\"profile_background_tile\":false,\"statuses_count\":1100,\"lang\":\"ru\",\"profile_link_color\":\"0084B4\",\"id\":386522307,\"following\":null,\"protected\":false,\"favourites_count\":13,\"profile_text_color\":\"333333\",\"description\":\"160 ????????\",\"verified\":false,\"contributors_enabled\":false,\"profile_sidebar_border_color\":\"C0DEED\",\"name\":\"???????? ??????\",\"profile_background_color\":\"C0DEED\",\"created_at\":\"Fri Oct 07 12:44:01 +0000 2011\",\"default_profile_image\":false,\"followers_count\":46,\"profile_image_url_https\":\"https://si0.twimg.com/profile_images/2785804589/b0b355c75d3f77658fc94ec05a7bb5af_normal.jpeg\",\"geo_enabled\":true,\"profile_background_image_url\":\"http://a0.twimg.com/images/themes/theme1/bg.png\",\"profile_background_image_url_https\":\"https://si0.twimg.com/images/themes/theme1/bg.png\",\"follow_request_sent\":null,\"entities\":{\"description\":{\"urls\":[]},\"url\":{\"urls\":[{\"expanded_url\":null,\"indices\":[0,29],\"url\":\"http://goodfoto.blogspot.com/\"}]}},\"url\":\"http://goodfoto.blogspot.com/\",\"utc_offset\":7200,\"time_zone\":\"Athens\",\"notifications\":null,\"profile_use_background_image\":true,\"friends_count\":46,\"profile_sidebar_fill_color\":\"DDEEF6\",\"screen_name\":\"LonliLokli2000\",\"id_str\":\"386522307\",\"profile_image_url\":\"http://a0.twimg.com/profile_images/2785804589/b0b355c75d3f77658fc94ec05a7bb5af_normal.jpeg\",\"listed_count\":1,\"is_translator\":false},\"coordinates\":null,\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"}}";
Status status = DataObjectFactory.createStatus(json);
// when
String lang = status.getIsoLanguageCode();
// then
assertEquals("en", lang);
}
示例12: testReturningNullForMissingIsoLanguageCode
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void testReturningNullForMissingIsoLanguageCode() throws Exception {
// given
String json = "{\"contributors\":null,\"text\":\"@belbeer After four years of study in radiotechnical college I realized that the language skills are much more useful than fucking math.\",\"geo\":null,\"retweeted\":false,\"in_reply_to_screen_name\":\"belbeer\",\"truncated\":false,\"entities\":{\"urls\":[],\"hashtags\":[],\"user_mentions\":[{\"id\":74987101,\"name\":\"belbeer\",\"indices\":[0,8],\"screen_name\":\"belbeer\",\"id_str\":\"74987101\"}]},\"in_reply_to_status_id_str\":\"297250346298904576\",\"id\":297265580690513920,\"source\":\"web\",\"in_reply_to_user_id_str\":\"74987101\",\"favorited\":false,\"in_reply_to_status_id\":297250346298904576,\"retweet_count\":0,\"created_at\":\"Fri Feb 01 08:50:12 +0000 2013\",\"in_reply_to_user_id\":74987101,\"id_str\":\"297265580690513920\",\"place\":null,\"user\":{\"location\":\"where am i?\",\"default_profile\":true,\"profile_background_tile\":false,\"statuses_count\":1100,\"lang\":\"ru\",\"profile_link_color\":\"0084B4\",\"id\":386522307,\"following\":null,\"protected\":false,\"favourites_count\":13,\"profile_text_color\":\"333333\",\"description\":\"160 ????????\",\"verified\":false,\"contributors_enabled\":false,\"profile_sidebar_border_color\":\"C0DEED\",\"name\":\"???????? ??????\",\"profile_background_color\":\"C0DEED\",\"created_at\":\"Fri Oct 07 12:44:01 +0000 2011\",\"default_profile_image\":false,\"followers_count\":46,\"profile_image_url_https\":\"https://si0.twimg.com/profile_images/2785804589/b0b355c75d3f77658fc94ec05a7bb5af_normal.jpeg\",\"geo_enabled\":true,\"profile_background_image_url\":\"http://a0.twimg.com/images/themes/theme1/bg.png\",\"profile_background_image_url_https\":\"https://si0.twimg.com/images/themes/theme1/bg.png\",\"follow_request_sent\":null,\"entities\":{\"description\":{\"urls\":[]},\"url\":{\"urls\":[{\"expanded_url\":null,\"indices\":[0,29],\"url\":\"http://goodfoto.blogspot.com/\"}]}},\"url\":\"http://goodfoto.blogspot.com/\",\"utc_offset\":7200,\"time_zone\":\"Athens\",\"notifications\":null,\"profile_use_background_image\":true,\"friends_count\":46,\"profile_sidebar_fill_color\":\"DDEEF6\",\"screen_name\":\"LonliLokli2000\",\"id_str\":\"386522307\",\"profile_image_url\":\"http://a0.twimg.com/profile_images/2785804589/b0b355c75d3f77658fc94ec05a7bb5af_normal.jpeg\",\"listed_count\":1,\"is_translator\":false},\"coordinates\":null}";
Status status = DataObjectFactory.createStatus(json);
// when
String lang = status.getIsoLanguageCode();
// then
assertNull(lang);
}
示例13: testKryoSerialization
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public void testKryoSerialization() throws TwitterException, ClassNotFoundException {
Status status;
status = DataObjectFactory.createStatus(TEST_STATUS_JSON);
ByteBuffer buffer = ByteBuffer.allocate(512);
kryo.writeObject(buffer, status);
System.out.println(buffer.position() + " vs. " + TEST_STATUS_JSON.length());
buffer.rewind();
Status deserializedStatus = (Status) kryo.readObject(buffer, Class.forName("twitter4j.internal.json.StatusJSONImpl"));
assertNotNull(deserializedStatus);
assertEquals(status, deserializedStatus);
}
示例14: parse
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
private Status parse(String rawJson){
try {
Status parsed = DataObjectFactory.createStatus(rawJson);
return parsed;
} catch (TwitterException e) {
log.warn("Invalid tweet json -> " + rawJson, e);
return null;
}
}
示例15: loadStatusesMap
import twitter4j.json.DataObjectFactory; //导入方法依赖的package包/类
public static Map<String, Status> loadStatusesMap(String hostname, String dbname, String collName, boolean unique, String lang, String[] ids) {
Map<String, Status> statuses = new HashMap<String, Status>();
DBCollection collection = getCollection(hostname, dbname, collName);
BasicDBObject query = new BasicDBObject();
if(ids != null && ids.length > 0) {
query.put("id", new BasicDBObject("$in", ids));
}
if(lang != null) {
query.put("lang", lang);
}
int k = 0;
DBCursor cursor = collection.find(query);
while(cursor.hasNext()) {
if(++k%1000==0) {
System.out.print(".");
if(k%100000==0) {
System.out.println(" " + k);
}
}
DBObject obj = cursor.next();
String rawJSON = obj.toString();
try {
Status status = DataObjectFactory.createStatus(rawJSON);
Status rt = status.getRetweetedStatus();
if(rt != null && !unique) {
if(!statuses.containsKey(rt.getId()))
statuses.put(Long.toString(rt.getId()), rt);
if(!statuses.containsKey(status.getId()))
statuses.put(Long.toString(status.getId()), status);
}
else {
if(!statuses.containsKey(status.getId()))
statuses.put(Long.toString(status.getId()), status);
}
} catch (TwitterException e) {
}
}
return statuses;
}