Using Twitter API With Java

You can see Consumer key & Access token generation on below screen shot

Using Twitter API With Java


We required both types credentials for interacting the Twitter service

Please find an example and it's output about how Twitter4j Connecting with Twitter service.

package test.twitter;

import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;

//Twitter API With Java Example
public class Twitter4jExample {
public static void main(String args[]) {
Twitter twitter = new TwitterFactory().getInstance();
// Twitter Consumer key & Consumer Secret
twitter.setOAuthConsumer("l5HHK9Zif6cbQLVTm2lzTQ", "3Jp8X9B78MijlxgFXrp76S5mT2QkqK1iOytZ8z1sc");
// Twitter Access token & Access token Secret
twitter.setOAuthAccessToken(new AccessToken("371118809-g8MSGnFNZVe1ZDHynOQF4x83vIsCkJAinI4EIhRW",
try {
// Getting Twitter Timeline using Twitter4j API
ResponseList statusReponseList = twitter.getUserTimeline(new Paging(1, 5));
for (Status status : statusReponseList) {
// Post a Tweet using Twitter4j API
Status status = twitter.updateStatus("Hello");
("Successfully updated the status to [" + status.getText() + "].");
} catch (Exception e) {
Change CXF Character Encoding
Getting IP Address Using CXF
Apache CXF Logging
RESTful Java Client Using HttpClient


Previous 1 2

Your email address will not be published. Required fields are marked *