Twitter REST API and Streaming API
来源:互联网 发布:linux里sleep函数 编辑:程序博客网 时间:2024/05/21 15:06
Like my last blog, Twitter portlet of Liferay uses REST API. Twitter returns JSON Object, we just need to interpret it and store in our database. The bad thing for REST API is rate limit. In my previous blog, I mentioned that. For unauthenticated user, 150 per hour; authenticated user, 350 per hour. For a large website, it's not enough. The good news is we have another choice Streaming API.
For my specific task, I just need to user streams. I also don't want to write from scratch because I don't know how to codeO(∩_∩)O~. Then I run into Twitter4jhttp://twitter4j.org/en/index.html. It has all APIs for REST API and Streaming API we want. So actually we don't need to interpret JSON Object, we can ask Twitter4j do for us.
My task is: get real-time tweets and display in my own twitter portlet.
public class Test {public static void main(String[] args) {System.out.println("Start listening Twitter Streaming API....");TwitterStatusListener listener = context.getBean("twitterStatusListener",TwitterStatusListener.class);TwitterStream twitterStream = new TwitterStreamFactory().getInstance();twitterStream.addListener(listener);List<Feed> feeds = feedManager.getAllFeeds();//Here is to get Feeds which store twitterUserId.long[] followArray = new long[feeds.size()];for (int i = 0; i < feeds.size(); i++) {followArray[i] = feeds.get(i).getTwitterUserId();}twitterStream.filter(new FilterQuery(followArray)); //The FilterQuery just accepts long[] array of twitterUserids}}If you want to do more coding, go to look at twitter4j-example. It's very useful and clear. You can find at least one example for every API.
Another issue I run into is if we call twitterStream.filter(new FilterQuery(followArray)); once, it'll set up a new connection for us. Streaming API is used for a long-live connection, If we disconnect and reconnect frequently, our project will also hit rate limit.
- Twitter REST API and Streaming API
- Twitter Streaming API的调用
- 转 -- 使用 Twitter REST API
- 01-Twitter Streaming API的调用
- Rest API registration and login
- twitter api
- twitter api
- 用twitcurl C++库访问Twitter REST API 1.1
- REST API
- REST api
- rest api
- REST API
- REST API
- Rest API
- Deploy Composer and Generate REST API
- API&REST API
- Twitter API中文文档
- Twitter API中文文档
- 【Jason Lab】在工作流中使用异步调用
- CF 246C Beauty Pageant
- How does Twitter Portlet in Liferay Marketplace work?
- 人生最重要的不是努力,是方向。
- 腾讯搞什么啊,一个比赛规则还三天两头变
- Twitter REST API and Streaming API
- 小试 Node.JS 之 解析html
- 数值的整数次方 和开根号
- 因为年轻,可以去闯北上广
- ios audio/avfoundaion blogs
- 草稿
- 设计模式(14)-行为型-命令模式(Command)
- Windows Presentation Foundation Introduction(I) - Overview
- 未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序。