I have a tweet that I had stored in a file. I want to extract the user as a json object and store it in a different file. The following results in java.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 can I set jsonStoreEnabled
to true
? Or, is there another way of doing it? I don't have to stick with Twitter4j
to create jsonUser
. I tried json-simple
, but the resulting String is not parsable with Twitter4j.
TwitterObjectFactory has a variable called registeredAtleastOnce that if false you will get java.lang.IllegalStateException: Apparently jsonStoreEnabled is not set to true.
. You can see this page
TwitterObjectFactory
So, if you don't want that error you will have to make once call to the Twitter API, for example for the first line of your file
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
In that way you wouldn't get that error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With