Sending a private message to another Twitter user

In this recipe, you'll learn how to send a private message to another Twitter user from a Spring web application. Note that the user who is the recipient has to be a follower of the user who is the sender.

Getting Ready

This recipe uses the code from the Connecting to Twitter recipe.

How to do it…

In the TwitterController class, in the tw() method, use the Twitter object to send a private message to another Twitter user:

twitter.directMessageOperations().sendDirectMessage("jeromejaglale", "Hey Jerome, I'm just testing your recipe.");

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.