Improve your contact center performance. See how you can make a difference.
Watch Now
Engage and build your ICT audience with CIOL online advertising.
Know more
Add the Twitter service Click on the Java tab. To the class named Page1, add a new method named getTweets, as follows:
protected void getTweets() { }
You will need to call the above method in the init() method. In this method add the statement this.getTweets(); below the comment which says:
// TODO - add your own initialization code here
Click on the Services tab (on the left pane). Expand the 'Web Services' node. Next, expand Twitter>What Are You Doing Service>[direct_message .{format}]. Drag and drop getDirectMessagesToMe to the getTweets method body ? i.e. drop it between the opeing ({) and the closing (}) braces. A window called 'Customize GET Saas Service' will pop up. Click on 'Ok' on this window. NetBeans will automatically create all the required code to consume the REST web service. Next we only require to write a few lines of code to display the direct messages on the web page.
Display the Tweets Switch to the design mode by clicking on the Design tab. From the palette, in the right pane, expand Woodstock Basic. Drag and drop 'Static Text' component onto the design. Right click on the 'Static Text' component and select 'Add Binding Attribute'. Next, in the Java code, add the following import statements at the top:
import java.util.List;
Add the following statement just above the closing braces of the try block of getTweets( ) method:
this.displayTweets(result);
With this, we will pass the result of the web service call to another method called displayTweets where we will parse through the result/response of the service and display it.The code for displayTweets() looks like this:
protected void displayTweets(RestResponse result) throws JAXBException { twitter.whatareyoudoingservice.twitterresponse.DirectMessages directMessagesObject = result.getDataAsObject(twitter.whatareyoudoingservice.twitterresponse.DirectMessages.class); this.staticText1.setText(""); this.staticText1.setEscape(false); List<twitter.whatareyoudoingservice.twitterresponse.DirectMessageType> directMessages = directMessagesObject.getDirectMessage(); twitter.whatareyoudoingservice.twitterresponse.DirectMessageType directMessage = null; for(int i=0;i<directMessages.size();i++) { directMessage = directMessages.get(i); this.staticText1.setText(this.staticText1.getText()+"<br />"+directMessage.getSenderScreenName()+":"+directMessage.getText()); } }
Add the above method to the Page1 class.
Run the application by clicking on Run>Run Main Project. When prompted, enter a Twitter username and password (using which you login at Twitter.com). The output will show sender and the direct tweets.
<< PREVIOUS