Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:04:46+00:00 2026-06-11T01:04:46+00:00

I am developing an application which interacts with Twitter using twitter4j API. Does this

  • 0

I am developing an application which interacts with Twitter using twitter4j API. Does this API provide an event listener for incomning direct messages?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:04:47+00:00Added an answer on June 11, 2026 at 1:04 am

    Please find the implementation in the following code.
    Please add the twitter4j-core-2.2.6.jar & twitter4j-stream-2.2.6.jar to your build path.

    package com.apt.java.test.twitterdemo;
    
    import java.util.List;
    
    import twitter4j.DirectMessage;
    import twitter4j.Status;
    import twitter4j.StatusDeletionNotice;
    import twitter4j.StatusListener;
    import twitter4j.Twitter;
    import twitter4j.TwitterException;
    import twitter4j.TwitterFactory;
    import twitter4j.TwitterStream;
    import twitter4j.TwitterStreamFactory;
    import twitter4j.User;
    import twitter4j.UserList;
    import twitter4j.UserStreamListener;
    import twitter4j.auth.AccessToken;
    import twitter4j.conf.ConfigurationBuilder;
    
    public class TwitterDemo {
        private TwitterStream twitterStream;
        private void initConfiguration(){
            ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true)
              .setOAuthConsumerKey("YOUR CONSUMER KEY")
              .setOAuthConsumerSecret("YOUR CONSUMER SECRET");
    
            TwitterStreamFactory twitterStreamFactory = new TwitterStreamFactory(cb.build());
            twitterStream = twitterStreamFactory.getInstance(new AccessToken("YOUR ACCESS TOKEN", "YOUR ACCESS TOKEN SECRET"));
            twitterStream.addListener(userStreamListener);
            twitterStream.user();
    
        }
    
        UserStreamListener userStreamListener = new UserStreamListener() {
    
            @Override
            public void onException(Exception arg0) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onTrackLimitationNotice(int arg0) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onStatus(Status status) {
                // TODO Auto-generated method stub
                System.out.println(status.getText());
            }
    
            @Override
            public void onScrubGeo(long arg0, long arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onDeletionNotice(StatusDeletionNotice arg0) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserProfileUpdate(User arg0) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListUpdate(User arg0, UserList arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListUnsubscription(User arg0, User arg1, UserList arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListSubscription(User arg0, User arg1, UserList arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListMemberDeletion(User arg0, User arg1, UserList arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListMemberAddition(User arg0, User arg1, UserList arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListDeletion(User arg0, UserList arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUserListCreation(User arg0, UserList arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUnfavorite(User arg0, User arg1, Status arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onUnblock(User arg0, User arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onRetweet(User arg0, User arg1, Status arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onFriendList(long[] arg0) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onFollow(User arg0, User arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onFavorite(User arg0, User arg1, Status arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onDirectMessage(DirectMessage message) {
                // TODO Auto-generated method stub
                System.out.println(message.getText());
            }
    
            @Override
            public void onDeletionNotice(long arg0, long arg1) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onBlock(User arg0, User arg1) {
                // TODO Auto-generated method stub
    
            }
        };
    
        public static void main(String[] args){
            TwitterDemo demo = new TwitterDemo();
            demo.initConfiguration();
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a MVC3 application which interacts with a db. I'm using a form
I developing application which using geo-location. Should i ask user right for this when
When developing an application which mostly interacts with a database, what is a good
I am developing a C# web application in VS 2008 which interacts with my
I am developing application in flex 3 which interacts with the Google feeds to
We are developing a application which interacts with Data-warehouse and retrieves data to do
I'm developing a spatial ranking application using GeoDjango + PostGIS. Basically what it does
I developing an application which works with Google API, according to my understanding. def
The background I'm developing a REST API for a C#.NET web application using WCF.
I am developing application which is having Gujarati font in text-view but my problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.