简体   繁体   English

使用twitter4j保存和加载推文

[英]Save and load tweets using twitter4j

I want to write an Android app that gets tweets using twitter4j. 我想编写一个使用twitter4j获取推文的Android应用。 I want to make the app save the downloaded tweets (for example in a database) and make the timeline appear when the app is started without internet connection or before the timeline was downloaded. 我想让该应用保存已下载的tweet(例如在数据库中),并在没有互联网连接的情况下启动该应用或在下载时间线之前显示时间线。 This functionality is implemented in the official Twitter Android app. 此功能在官方的Twitter Android应用中实现。

twitter4j stores tweets using the StatusJSONImpl class. twitter4j使用StatusJSONImpl类存储推文。

I do not know how to instanciate this class with custom data (the tweets that the app obtained in a former session). 我不知道如何使用自定义数据(该应用在前一个会话中获得的推文)来实例化此类。

I cannot extend the class because all the properties are private. 我不能扩展该类,因为所有属性都是私有的。 Do I have to change the class itself and compile the entire twitter4j library (i dont even know if thats possible) or is there an easier way? 我是否必须更改类本身并编译整个twitter4j库(我什至不知道那是否可行)还是有更简单的方法?

Instead of storing the query from twitter4j directly, you should instead build your own interpretation of what the stream is and store that. 与其直接存储来自twitter4j的查询,不如构建自己对流的解释并将其存储。 Then when you have no internet connection, you don't even talk to twitter4j, instead you just display what you have stored. 然后,当您没有互联网连接时,您甚至都不会与twitter4j交谈,而是只显示您存储的内容。 You can then use twitter4j (when you have a connection) to update you on what the latest tweets are and keep your store up to date. 然后,您可以使用twitter4j(有连接时)向您更新最新的tweet,并保持商店最新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM