本文整理汇总了Java中twitter4j.json.DataObjectFactory类的典型用法代码示例。如果您正苦于以下问题:Java DataObjectFactory类的具体用法?Java DataObjectFactory怎么用?Java DataObjectFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataObjectFactory类属于twitter4j.json包,在下文中一共展示了DataObjectFactory类的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: AbstractTwitterStatusesFilterDataset
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
/**
* Construct with the given Twitter API credentials and buffer
*
* @param query
* the query
* @param token
* the Twitter api authentication credentials
* @param buffer
* the backing buffer for storing data before consumption from
* the stream
*/
public AbstractTwitterStatusesFilterDataset(FilterQuery query, TwitterAPIToken token, BlockingDroppingQueue<T> buffer)
{
super(buffer);
final TwitterStream twitterStream = new TwitterStreamFactory(makeConfiguration(token)).getInstance();
twitterStream.addListener(new StatusAdapter() {
@Override
public void onStatus(Status status) {
try {
registerStatus(status, DataObjectFactory.getRawJSON(status));
} catch (final InterruptedException e) {
// ignore
}
}
});
twitterStream.filter(query);
}
示例4: AbstractTwitterStreamDataset
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
/**
* Construct with the given Twitter API credentials and buffer
*
* @param token
* the Twitter api authentication credentials
* @param buffer
* the backing buffer for storing data before consumption from
* the stream
*/
public AbstractTwitterStreamDataset(TwitterAPIToken token, BlockingDroppingQueue<T> buffer) {
super(buffer);
final TwitterStream twitterStream = new TwitterStreamFactory(makeConfiguration(token)).getInstance();
twitterStream.addListener(new StatusAdapter() {
@Override
public void onStatus(Status status) {
try {
registerStatus(status, DataObjectFactory.getRawJSON(status));
} catch (final InterruptedException e) {
// ignore
}
}
});
twitterStream.sample();
}
示例5: main
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
/**
* Usage: java twitter4j.examples.json.SaveRawJSON
*
* @param args String[]
*/
public static void main(String[] args) {
Twitter twitter = new TwitterFactory().getInstance();
System.out.println("Saving public timeline.");
try {
new File("statuses").mkdir();
List<Status> statuses = twitter.getHomeTimeline();
for (Status status : statuses) {
String rawJSON = DataObjectFactory.getRawJSON(status);
String fileName = "statuses/" + status.getId() + ".json";
storeJSON(rawJSON, fileName);
System.out.println(fileName + " - " + status.getText());
}
System.out.print("\ndone.");
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);
}
}
示例6: 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);
}
}
示例7: testGetMentions
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
public void testGetMentions() throws Exception {
Status status = twitter2.updateStatus("@" + id1.screenName + " reply to id1 " + new java.util.Date());
assertNotNull(DataObjectFactory.getRawJSON(status));
List<Status> statuses = twitter1.getMentionsTimeline();
assertNotNull(DataObjectFactory.getRawJSON(statuses));
assertEquals(statuses.get(0), DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(statuses.get(0))));
assertTrue(statuses.size() > 0);
statuses = twitter1.getMentionsTimeline(new Paging(1));
assertNotNull(DataObjectFactory.getRawJSON(statuses));
assertEquals(statuses.get(0), DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(statuses.get(0))));
assertTrue(statuses.size() > 0);
statuses = twitter1.getMentionsTimeline(new Paging(1));
assertNotNull(DataObjectFactory.getRawJSON(statuses));
assertEquals(statuses.get(0), DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(statuses.get(0))));
assertTrue(statuses.size() > 0);
statuses = twitter1.getMentionsTimeline(new Paging(1, 1l));
assertNotNull(DataObjectFactory.getRawJSON(statuses));
assertEquals(statuses.get(0), DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(statuses.get(0))));
assertTrue(statuses.size() > 0);
statuses = twitter1.getMentionsTimeline(new Paging(1l));
assertNotNull(DataObjectFactory.getRawJSON(statuses));
assertEquals(statuses.get(0), DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(statuses.get(0))));
assertTrue(statuses.size() > 0);
}
示例8: testSavedSearches
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
public void testSavedSearches() throws Exception {
List<SavedSearch> list = twitter1.getSavedSearches();
assertNotNull(DataObjectFactory.getRawJSON(list));
for (SavedSearch savedSearch : list) {
twitter1.destroySavedSearch(savedSearch.getId());
}
SavedSearch ss1 = twitter1.createSavedSearch("my search");
assertNotNull(DataObjectFactory.getRawJSON(ss1));
assertEquals(ss1, DataObjectFactory.createSavedSearch(DataObjectFactory.getRawJSON(ss1)));
assertEquals("my search", ss1.getQuery());
assertEquals(-1, ss1.getPosition());
list = twitter1.getSavedSearches();
assertNotNull(DataObjectFactory.getRawJSON(list));
assertEquals(list.get(0), DataObjectFactory.createSavedSearch(DataObjectFactory.getRawJSON(list.get(0))));
// http://code.google.com/p/twitter-api/issues/detail?id=1032
// the saved search may not be immediately available
assertTrue(0 <= list.size());
try {
SavedSearch ss2 = twitter1.destroySavedSearch(ss1.getId());
assertEquals(ss1, ss2);
} catch (TwitterException te) {
// sometimes it returns 404 or 500 when its out of sync.
assertTrue(404 == te.getStatusCode() || 500 == te.getStatusCode());
}
}
示例9: 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());
}
示例10: testOEmbed
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
public void testOEmbed() throws TwitterException {
OEmbed oembed = twitter1.getOEmbed(new OEmbedRequest(240192632003911681L, "http://samuraism.com/"));
assertNotNull(DataObjectFactory.getRawJSON(oembed));
assertEquals(oembed, DataObjectFactory.createOEmbed(DataObjectFactory.getRawJSON(oembed)));
assertNotNull(oembed.getHtml());
assertEquals("Jason Costa", oembed.getAuthorName());
assertEquals("https://twitter.com/jasoncosta/statuses/240192632003911681", oembed.getURL());
assertEquals("1.0", oembed.getVersion());
assertEquals(3153600000L, oembed.getCacheAge());
assertEquals("https://twitter.com/jasoncosta", oembed.getAuthorURL());
assertTrue(0 < oembed.getWidth());
oembed = twitter1.getOEmbed(new OEmbedRequest(273685580615913473L, "http://samuraism.com/"));
}
示例11: testBlockMethods
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
public void testBlockMethods() throws Exception {
User user1 = twitter2.createBlock(id1.screenName);
assertNotNull(DataObjectFactory.getRawJSON(user1));
assertEquals(user1, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(user1)));
User user2 = twitter2.destroyBlock(id1.screenName);
assertNotNull(DataObjectFactory.getRawJSON(user2));
assertEquals(user2, DataObjectFactory.createUser(DataObjectFactory.getRawJSON(user2)));
PagableResponseList<User> users = twitter1.getBlocksList();
assertNotNull(DataObjectFactory.getRawJSON(users));
assertEquals(users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0))));
assertEquals(1, users.size());
assertEquals(39771963, users.get(0).getId());
IDs ids = twitter1.getBlocksIDs();
assertNull(DataObjectFactory.getRawJSON(users));
assertNotNull(DataObjectFactory.getRawJSON(ids));
assertEquals(1, ids.getIDs().length);
assertEquals(39771963, ids.getIDs()[0]);
ids = twitter1.getBlocksIDs(-1);
assertTrue(ids.getIDs().length > 0);
}
示例12: testSuggestion
import twitter4j.json.DataObjectFactory; //导入依赖的package包/类
public void testSuggestion() throws Exception {
ResponseList<Category> categories = twitter1.getSuggestedUserCategories();
assertTrue(categories.size() > 0);
assertNotNull(DataObjectFactory.getRawJSON(categories));
assertNotNull(DataObjectFactory.getRawJSON(categories.get(0)));
assertEquals(categories.get(0), DataObjectFactory.createCategory(DataObjectFactory.getRawJSON(categories.get(0))));
ResponseList<User> users = twitter1.getUserSuggestions(categories.get(0).getSlug());
assertTrue(users.size() > 0);
assertNull(users.get(0).getStatus());
assertNotNull(DataObjectFactory.getRawJSON(users));
assertNotNull(DataObjectFactory.getRawJSON(users.get(0)));
assertEquals(users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0))));
users = twitter1.getMemberSuggestions(categories.get(0).getSlug());
assertTrue(users.size() > 0);
assertNotNull(users.get(0).getStatus());
assertNotNull(DataObjectFactory.getRawJSON(users));
assertNotNull(DataObjectFactory.getRawJSON(users.get(0)));
assertEquals(users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0))));
}
示例13: 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();
}
示例14: 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));
}
示例15: 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());
}