Python – API.send_direct_message() in Tweepy
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
send_direct_message() method of the
API class in Tweepy module is used to send a direct message as the authenticated user.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Syntax : API.send_direct_message(parameters)
- recipient_id : ID of the recipient.
- text : text of the direct message.
- attachment_type : attachment media or location to be sent.
- attachment_media_id : ID of the attachment media to be sent.
Returns : an object of class DirectMessage
Example 1 :
This is a Direct Message.
Example 2 : Sending a direct message with the following media attachment :