How does Twitter Portlet in Liferay Marketplace work?

What I tested in my small project is I have a list of TwitterUserId, I need to get their real-time tweets which are posted on Twitter. 

The first thing I do was download a twitter portlet from Liferay marketplace http://www.liferay.com/marketplace. You can search Twitter and Liferay will give you two versions CE and EE. Let's see how to configure it.

1. Put the war file into your bundles/deploy package.

2. Start your Tomcat, login in to your Liferay

3. Select Add->Social->Twitter, add it to your public or private page.

4. Twitter Portlet will let you set up an Twitter account, this will go to Liferay's component which is under Control Panel->My Account->Social Network. Here you can configure Twitter Account(Your TwitterScreenName). 

For example: 

When I login in Twitter and Click my account photo or my name.  The linke below will be shown in the browser bar.

https://twitter.com/RujuanXing, Then the TwitterScreenName will  beRujuanXing

5. Then you go back to the page you've added Twitter portlet. It'll say "Your activities will be shown in Activities Portlet". Now you need to add Activities which is under Social category in your portal.

6. If you haven't done anything in your portal like posting a blog. Activities Portlet will say something like "NO activities Now". Next, you log in Twitter, and Tweet something and go back to your portal. Refresh it, Activities portlet will also say "No activites"! This is the most frustrating thing. I've spent half day to configure the thing again and again. I was wondering something is wrong when I deploy Twitter Portlet.

Now I know the best way to know what happens in Twitter Portlet is to read source code. https://github.com/liferay/liferay-plugins/tree/master/portlets/twitter-portlet

You can get the source code from the link above. The source code seems quite old. I also checked the newest one. The key problem doesn't change. We can gain a basic idea from the source code.

7. Let me explain what twiiter portlet work firstly. 

1) When we deploy twitter-portlet.war. It'll create one table for us which is named twitter_feed. In the table, it stores the twitterscreenname.


2) Next, Twitter portlet schedule a job to fetch Tweets from Twitter REST API. The job is configured in liferay-portlet.xml

3) When the user in the table tweets in Twitter, Twitter Portlet will get the data and store in socialactivitiy table which is a default table in Liferay.

4) Then, when we add Activities portlet in our page, Activities portlet will read socialactivitiy table and display data.


8. Why it doesn't work? 

1) The first thing I found is the REST API. It's different from other developers use. And API1.1 also doesn't use that. This is the key thing.

public class FeedLocalServiceImpl extends FeedLocalServiceBaseImpl {
	private static final String _URL = "http://twitter.com/statuses/user_timeline/";

This is the link which is used in the Twitter Portlet.  https://dev.twitter.com/docs/api/1/get/statuses/user_timeline The link shows URL for fetching a twitter user's timeline. They're different. You can directly add your screen name and copy them into your browser. Twitter responses "Sorry, the page doesn't exist!" If you use new URL like this:

public class FeedLocalServiceImpl extends FeedLocalServiceBaseImpl {

	private static final String _URL = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=";
Twitter REST API returns JSON Array to us. Twitter responses like this:


2) Another thing we need to know is Twitter portlet writes an entity named TwitterActivityInterpreterin social page. What does this class do?

If you take a look at Activities portlet, you'll find in the view.page. It just use a jstl tag to display all activities which is liferay-ui:social-activity. And in the corresponding ui taglib interpreter page.jsp. You'll see, the activity will be interpreted to SocialActivityFeedEntry and then, get property from SocialActivityFeedEntry. It's very interesting, right? But I spent almost one day to figure it out.

In Twitter portlet, we need to customize our display in Activities portlet. TwitterActivityInterpreter classis used for that. It displays tweets in three parts: portlet icon.jpg(logo), username with link to user profile in liferay, tweets with link to Tweet in Twitter.

One thing you also need to notice is adding the new interpreter to your twitter portlet as followed:

<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">

<liferay-portlet-app>
	<portlet>
		<portlet-name>1</portlet-name>
		<icon>/icon.png</icon>
		<scheduler-entry>
			<scheduler-event-listener-class>com.liferay.twitter.messaging.SynchronizeTwitterMessageListener</scheduler-event-listener-class>
			<trigger>
				<simple>
					<property-key>twitter.synchronization.interval</property-key>
					<time-unit>minute</time-unit>
				</simple>
			</trigger>
		</scheduler-entry>
		<social-activity-interpreter-class>com.liferay.twitter.social.TwitterActivityInterpreter</social-activity-interpreter-class>

I show two things in the above codes: Job and interpreter class.

This is the two key reasons I found of the twitter portlet. if we want to write our own twitter portlet, we're enough to start.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值