我正在尝试将收到的推文保存为 JSON 对象,但仍然无法从 Status
对象中获取 JSON 对象。
我检查了 JSONStoreEnabled()
并将其设置为 true。
API 说,
Note that raw JSON forms can be retrieved only from the same thread invoked the last method call and will become inaccessible once another method call.
我的所有东西都在 main() 方法中,所以我想这应该不是问题。
String tweet = TwitterObjectFactory.getRawJSON( status );
我检查过 status
对象包含所有信息,只是 getRawJSON
返回 null!。
如果有人能告诉我解决此问题的方法,我将不胜感激。
最佳答案
我在自己的应用中使用了这种方法。您可以在配置 Twitter4j 时尝试此操作。
使用 com.google.gson.Gson;
public Gson gson = new Gson();
ConfigurationBuilder config = new ConfigurationBuilder();
config.setJSONStoreEnabled(true);
config.setOAuthConsumerKey(Keys.TWITTER_KEY);
config.setOAuthConsumerSecret(Keys.TWITTER_SECRET);
config.setOAuthAccessToken(currentSession.getAuthToken().token);
config.setOAuthAccessTokenSecret(currentSession.getAuthToken().secret);
Configuration cf = config.build();
// For Twitter4j
enter code here
String statusJson = TwitterObjectFactory.getRawJSON(status); // status to json
关于java - twitter4j 4.0.2 getRawJSON() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32140296/