Tags
twitter , api
Asked 2 years ago
19 Sep 2021
Views 410
Connor

Connor posted

How to post tweet by api

How to post a tweet without human effort, i mean automatically, either I can use Twitter API or any library, Please help me to post automatically daily by machine
QuickIos

QuickIos
answered Sep 20 '21 00:00

Use python to do api call,
Tweepy python library can be used to post tweet by code

1. First of all, you need to create Twitter app at following link
https://developer.twitter.com/en/apps
and grab the API key , API secret key , Access token , Access token secret , you need it later.

2. install Tweepy python library , do it by following command :

pip install tweepy


3. code it for sending a tweet
3a. import Python library tweepy

import tweepy


3b. put API key, API secret key, Access token, Access token secret what you generated at https://developer.twitter.com/en/apps


consumer_key='***************'
consumer_secret_key='**********************************'
access_token='***********************************************'
access_token_secret='*****************************************'



3c. start authentication with tweepy by OAuthHandler

auth=tweepy.OAuthHandler(consumer_key,consumer_secret_key)
auth.set_access_token(access_token,access_token_secret)
connectapi=tweepy.API(auth)



3d. send tweet by update_status() method from tweepy library

tweetText="Auto posting tweeet "#this text will be posted 
 
connectapi.update_status(tweetText)
 


full code to post tweet Tweepy python library

import tweepy
consumer_key='***************'
consumer_secret_key='**********************************'
access_token='***********************************************'
access_token_secret='*****************************************'
auth=tweepy.OAuthHandler(consumer_key,consumer_secret_key)
auth.set_access_token(access_token,access_token_secret)
connectapi=tweepy.API(auth)
tweetText="Auto posting tweeet "#this text will be posted 
 
connectapi.update_status(tweetText)
Post Answer