Get user json from json tweet

I have a tweet that I saved in a file. I want to extract the user as a json object and save it in another file. Following results injava.lang.IllegalStateException: Apparently jsonStoreEnabled is not set to true.

String jsonStatus; //Content read from a file
Status status = TwitterObjectFactory.createStatus(jsonStatus); //no problem here
String jsonUser = TwitterObjectFactory.getRawJSON(status.getUser()); //Exception

How to install jsonStoreEnabledon true? Or is there any other way to do this? I do not need to stick Twitter4jto create jsonUser. I tried json-simple, but the resulting string is not processed using Twitter4j.

+4
source share
2 answers

It turns out the package org.jsonwas useful in this case:

public static String extractUser(String rawJSON) {
    return new org.json.JSONObject(rawJSON).get("user").toString();
}
0
source

TwitterObjectFactory RegisteredAtleastOnce, , false, java.lang.IllegalStateException: Apparently jsonStoreEnabled is not set to true.. TwitterObjectFactory , , API Twitter, ,

ConfigurationBuilder cb = new ConfigurationBuilder();
             cb.setDebugEnabled(true)
             .setOAuthConsumerKey(Ckey)
             .setOAuthConsumerSecret(CkeySecret)
             .setOAuthAccessToken(AToken))
             .setOAuthAccessTokenSecret(AtokenSecret)
             .setJSONStoreEnabled(true);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
String jsonStatus; //Content read from a file
Status status = TwitterObjectFactory.createStatus(jsonStatus); //your status
User u2 = t.showUser(status.getUser().getScreenName()); // you use the twitter object once
String jsonUser = TwitterObjectFactory.getRawJSON(status.getUser()); //now you won't get the error
System.out.print(jsonUser); //your happy json

,

+4

All Articles