Alternative for TwitterStream user() method in twitter4j 4.0.7 API as TwitterStream user() method is deprecated

oauth

#1
public final class PrintUserStream { 
public static void main(String[] args) throws TwitterException { 
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); 
    twitterStream.addListener(listener); 
    // user() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. 
    twitterStream.user(); 
} 

static UserStreamListener listener = new UserStreamListener() { 
    public void onStatus(Status status) { 
    } 

    public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { 
    } 

    public void onDeletionNotice(long directMessageId, long userId) { 
    } 

    public void onTrackLimitationNotice(int numberOfLimitedStatuses) { 
    } 

    public void onScrubGeo(long userId, long upToStatusId) { 
    } 

    public void onFriendList(long[] friendIds) { 
    } 

    public void onFavorite(User source, User target, Status favoritedStatus) { 
    } 

    public void onUnfavorite(User source, User target, Status unfavoritedStatus) { 
    } 

    public void onFollow(User source, User followedUser) { 
    } 

    public void onRetweet(User source, User target, Status retweetedStatus) { 
    } 

    public void onDirectMessage(DirectMessage directMessage) { 
    } 

    public void onUserListMemberAddition(User addedMember, User listOwner, UserList list) { 
    } 

    public void onUserListMemberDeletion(User deletedMember, User listOwner, UserList list) { 
    } 

    public void onUserListSubscription(User subscriber, User listOwner, UserList list) { 
    } 

    public void onUserListUnsubscription(User subscriber, User listOwner, UserList list) { 
    } 

    public void onUserListCreation(User listOwner, UserList list) { 
    } 

    public void onUserListUpdate(User listOwner, UserList list) { 

    } 

    public void onUserListDeletion(User listOwner, UserList list) { 
    } 

    public void onUserProfileUpdate(User updatedUser) { 
    } 

    public void onBlock(User source, User blockedUser) { 
    } 

    public void onUnblock(User source, User unblockedUser) { 
    } 

    public void onException(Exception ex) { 
    } 
}; 

In the above code,

twitterStream.user(); is deprecated which earlier would call the UserStreamListener overloaded methods according to the event occurs on twitter stream. Now the method is deprecated. Then which method should be used in place of twitterStream.user() method so that I can call the overloaded method according to the event occured on twitter userStream.

Could someone please help?


#2

The things that UserStream used to be able to do is now the Activity API https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium

There is no support for this API in Twitter4J yet, it’s still in the works: https://github.com/Twitter4J/Twitter4J/issues/306


#3

Hi IgorBrigadir,

Thanks for you great help.

May I know, is there any workaround means how much time it can take to provide support in twitter4j 4.0.7 for UserStream.

Thanks,
Amit


#4

I have no idea how long it would take to add that to Twitter4J, but if you want to see a working example of Activity API there’s this one: https://github.com/twitterdev/account-activity-dashboard


#5

Is there any code block in java which will show demonstration for twitter webhook like

you given in previous mail thread??