English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Using Python to chirp

Before using Tweet in Python, we must follow some steps.

Steps1-First, we must have a high-volume speaker profile and then we must add it along with our phone number.

First go to-Settings->Add phone->Add number->Confirm->Save.

We must follow these steps and then turn off all text notifications.

Steps2-Set up a new application.

Follow-Twitter application->Create a new application->Leave the callback URL empty->Create Twitter application.

Then display the message "Your application has been created. You can view and adjust the settings of the application."

Steps3-By default, the access permission of tweets is read-only. To send a tweet, a write permission is required.

Follow-Permissions tab->What type of access permissions does your application need?->Select Read and Write->Update settings.

Display such messages as "Permission settings have been successfully updated. Changes may take some time to reflect."

Steps4-Take some time to get the keys and access tokens.

Follow-Keys and Access Tokens tab.

Click to create my access token.

Display "Your application access token has been successfully generated"

Then, verify the access token/Secret-and read or write permissions.

Steps5-Finally is installtweety. The command is pip install tweety.

Publish a simple tweet

Example Code

# -*- coding: utf-8 -*-
"""
Created on Wed Oct 17 06:00:58 2018
@author: Satyajit
"""
import tweepy 
# personal details 
my_consumer_key = "customer_key"
my_consumer_secret = "secret_no"
my_access_token = "token_no"
my_access_token_secret = "secret_token"
# authentication of consumer key and secret 
my_auth = tweepy.OAuthHandler(my_consumer_key, my_consumer_secret) 
# Authentication of access token and secret 
my_auth.set_access_token(my_access_token, my_access_token_secret) 
my_api = tweepy.API(my_auth)
my_api.update_status(status = "Hi All Of my Friends!!!!")

Publish Media File

Example Code

import tweepy 
# personal information 
my_consumer_key = "customer_key"
my_consumer_secret = "secret_no"
my_access_token = "token_no"
my_access_token_secret = "secret_token"
# Authentication 
my_auth = tweepy.OAuthHandler(my_consumer_key, my_consumer_secret) 
my_auth.set_access_token(my_access_token, my_access_token_secret) 
my_api = tweepy.API(my_auth) 
my_tweet = "tweet msg" 
my_image_path = "path of the image"
# To attach the media file 
my_status = my_api.update_with_media(my_image_path, my_tweet)  
my_api.update_status(my_status = my_tweet)