DEV Community

Cover image for How to change Twitter Source Label
Sunil Aleti
Sunil Aleti

Posted on • Updated on

How to change Twitter Source Label

You might have seen some people using completely different source labels.

tweet

Well, today we will see how to change the Twitter source label

First, we need to have a Twitter developer account, if you don't have.

1) Just navigate to Twitter Developer website

2) Just fill out the form with details about ‘what you want to do with their API’. This process may take like 10 minutes and you will get a verification email instantly once you submitted the form.

Alt Text


After getting approval from Twitter. Now we can create an app

1) Open this link and click on "create app"

2) Give your app a name, this name will be shown on your tweets as a source label. And you can't name an app which is already present.
Click on Next

Image description

3) Click on App settings
Image description

4) Under User authentication settings, click on Setup
Image description

5) Enable OAuth 1.0a
Image description

6) Select Read and write under App permissions
Image description

7) You can enter either your Instagram or Twitter profile link
Image description

8) Now click on the option called Keys and Tokens. You can see your Twitter API keys and Access Tokens by clicking on view keys button and generate button respectively.
Image description

9) Now you have access to Twitter APIs, to create a Twitter app, you need to download Python.

10) Now, open the file location of where you have installed python and navigate to "Scripts" folder
C:\Users\"YourUsername"\AppData\Local\Programs\Python\Python37\Scripts

Alt Text

11) Now, Open Command Prompt, and type cd, give space and paste your python file location and click enter

cd C:\Users\"YourUsername"\AppData\Local\Programs\Python\Python37\Scripts
Enter fullscreen mode Exit fullscreen mode

12) Now type the command and hit enter

pip install tweepy
Enter fullscreen mode Exit fullscreen mode

Alt Text

13) Once installed, close the command prompt. Now in the python scripts folder, right-click and click on New > text document to create a new document.

Alt Text

14) Now open that document and paste this code inside

import tweepy
auth = tweepy.OAuthHandler("CONSUMER KEY HERE", "CONSUMER KEY SECRET HERE")
auth.set_access_token("ACCESS TOKEN HERE", "ACCESS TOKEN SECRET HERE")
api = tweepy.API(auth)
tweet = input(" ")
api.update_status(status =(tweet))
print ("Done!")
Enter fullscreen mode Exit fullscreen mode

If you want to tweet with a media file like photo or video, you can use the below code

import tweepy
auth = tweepy.OAuthHandler("CONSUMER KEY HERE", "CONSUMER KEY SECRET HERE")
auth.set_access_token("ACCESS TOKEN HERE", "ACCESS TOKEN SECRET HERE")
api = tweepy.API(auth)
tweet = input("")
image="C:/Users/facadmin1/Downloads/introdev.PNG"  #Enter image location
api.update_with_media(image, tweet)
print ("Done!")
Enter fullscreen mode Exit fullscreen mode

To reply to tweet with your custom source label then copy the link of the tweet that you want to reply for twitter.com/aleti_sunil/status/135677656715.. and last "1356776567154876416" is the tweet id

import tweepy
auth = tweepy.OAuthHandler("CONSUMER KEY HERE", "CONSUMER KEY SECRET HERE")
auth.set_access_token("ACCESS TOKEN HERE", "ACCESS TOKEN SECRET HERE")
api = tweepy.API(auth)
tweet = input("")
api.update_status(tweet, in_reply_to_status_id = tweetid)
print ("Done!")
Enter fullscreen mode Exit fullscreen mode

Now replace the placeholders with your twitter APIs. Remember that there are 4 APIs to change – API Key, API Secret Key, Access Token, and Access Token Secret.
Once done, it should look like this

Alt Text

15) Now save the file and name it anything, but change the save as type to “All files” and add “.py” at the end of the file name to save it as a python file and click save.

16) Now open that .py file you just made. That’s it, you can type anything in this command line and click enter.
It will be tweeted as a new tweet.

Alt Text

That's it. Hola you finally did it

If you still have any queries, check out the video


Hope it's useful

A ❤️ would be Awesome 😊

Oldest comments (91)

Collapse
 
mahithchigurupati profile image
Mahith

That was great Sunil. Thanks for letting us know.

Collapse
 
sunilaleti profile image
Sunil Aleti

Thanks ☺️

Collapse
 
tomader910 profile image
Tomader910

i did all the steps (pretty sure correctly) and when i open the file it auto closes, what am i doing wrong?

Collapse
 
sunilaleti profile image
Sunil Aleti

In such case, Open cmd and enter "python -i filename"
Now it will work

Collapse
 
tomader910 profile image
Tomader910

can you show me a pic/video on how to do this exactly? im a bit confused [btw i named the file anything.py (its not anything.py.py its shows as anything.py)]

Thread Thread
 
sunilaleti profile image
Sunil Aleti

sure, please check the image below


alt

Thread Thread
 
tomader910 profile image
Info Comment hidden by post author - thread only accessible via permalink
Tomader910
 
sunilaleti profile image
Sunil Aleti

I think you haven't installed tweepy?
If not, Enter "pip install tweepy" in cmd

Thread Thread
 
tomader910 profile image
Tomader910 • Edited

please what do i do, idk what to do streamable.com/55jqod

Thread Thread
 
sunilaleti profile image
Sunil Aleti

The link is not working. Can you share once again

Thread Thread
 
tomader910 profile image
Tomader910
Thread Thread
 
tomader910 profile image
Tomader910

got it to work

Thread Thread
 
dying53 profile image
dying53

i had the same exact problem, how did you get it to work?

Thread Thread
 
tomader910 profile image
Tomader910

try downloading pip, make sure its for python

Thread Thread
 
dying53 profile image
dying53 • Edited

i have pip installed, but i still have the problem where it auto closes :(

Collapse
 
azukacchi profile image
Info Comment hidden by post author - thread only accessible via permalink
Azka

umm how do you exactly change the source label? in which part?
I've checked tweepy's documentation for API.update_status but for the source parameter it says:
"source – Source of the update. Only supported by Identi.ca. Twitter ignores this parameter."
I tried customizing the source and yes it didn't do anything.

Collapse
 
sunilaleti profile image
Sunil Aleti

tweepy actually takes the name of the app which you created.
In this article, I created an app with name "A Tesla Lover" and I'm able to change the source label, which you can see from the last tweet in this article.

Collapse
 
azukacchi profile image
Azka

Ah I see.. I think the problem is that I didn't enable my 3rd party authentication, so it just tweeted without any source label. Thank you!

Collapse
 
azukacchi profile image
Azka

i enabled the 3rd party authentication and regenerate all the tokens and keys, and still nothing came out on the source label; only my tweet. any idea?

Thread Thread
 
sunilaleti profile image
Sunil Aleti

hav u changed to read & write ?

Thread Thread
 
azukacchi profile image
Azka

yes i've changed the permission to read & write before i changed the 3rd party authentication. i've found the same issue on the link and i guess it'll take some time until the effect takes place. your code is handier, thank you!
gist.github.com/KonradIT/0bd7243eb...

Collapse
 
shyamraval13121 profile image
Shyam Raval

yes that worked out for me but now i want to change the name again and changing the app name in devloper website doesn't make any changes will it take some time to do all the changes please can you tell me ?

Collapse
 
hongjoochanist profile image
Info Comment hidden by post author - thread only accessible via permalink

why does mine look like this? :(( i tried redoing the steps but it wont changee

Collapse
 
sunilaleti profile image
Sunil Aleti

There might be some issue with ur code or process. Plz recheck once because many of them tried and its working for them

Collapse
 
mixerxarmy profile image
Info Comment hidden by post author - thread only accessible via permalink

Help please, what do i do :( It says it doesn't recognize the "pip install tweepy"

Collapse
 
shyamraval13121 profile image
Shyam Raval

hey i succesfully completed all the steps and it worked fine for me untill i realised that my twitter label has a speel mistake how do i change my twitter label again ?

Collapse
 
sunilaleti profile image
Sunil Aleti • Edited

You can edit the app name or create a new app it will work

Collapse
 
aksvins profile image
Aksvins

make a new app, do the same steps with the new keys and tokens.

Collapse
 
blancoharsh profile image
Harsh #34

great tutorial but I have a question, what if i have to reply ny specific tweet using the app, is there ay to do that?

Collapse
 
sunilaleti profile image
Sunil Aleti • Edited

Thanks, we can reply but we need to modify the code for that

Collapse
 
blancoharsh profile image
Harsh #34

Do you have the code for that? That would be very helpful

Thread Thread
 
sunilaleti profile image
Sunil Aleti • Edited

instead of using
api.update_status(status =(tweet))
use api.update_status("your reply", in_reply_to_status_id = tweetid)

Thread Thread
 
blancoharsh profile image
Harsh #34

ok but what if i want to reoky to a specific tweet?

Thread Thread
 
sunilaleti profile image
Sunil Aleti

Copy the link of the tweet

Ex: twitter.com/AndroidPolice/status/1... and last "1308397020034420736" is the tweet id

Thread Thread
 
blancoharsh profile image
Harsh #34

Thank You so much🙏

Collapse
 
arzikielt profile image
arzikiel tenebris

sorry im kinda retard, can you give me an example? because it didn't work on me (i'm new to this)

Collapse
 
sunilaleti profile image
Sunil Aleti • Edited

If you want to upload image or video in a tweet, use this

import tweepy
auth = tweepy.OAuthHandler("CONSUMER KEY HERE", "CONSUMER KEY SECRET HERE")
auth.set_access_token("ACCESS TOKEN HERE", "ACCESS TOKEN SECRET HERE")
api = tweepy.API(auth)
tweet = input("")
image="C:/Users/facadmin1/Downloads/introdev.PNG"  #Enter image location
api.update_with_media(image, tweet)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
k_edgarr profile image
Edgar

where do i put the image path

Collapse
 
sunilaleti profile image
Sunil Aleti

In 5th line, inside input enter the image location

Thread Thread
 
k_edgarr profile image
Edgar

figured it out that im supposed to put to // on the path or else it will have an error

Collapse
 
nonvieri profile image
nonvieri

unicode error ‘unicodeescape’ codec can’t decode bytes etc

Collapse
 
kiprono profile image
Kiprono

@nonvieri I'm getting the same error too. @sunilaleti what's the solution here?

Collapse
 
93luc0zade profile image
zayn’s refrigerator

hi is this possible on a Mac?? because I'm finding it really hard, I'd really appreciate the help.

Collapse
 
thisislexvt profile image
Carlos Alejandro

make a windows 10 VM

Collapse
 
btsprodz profile image
ja⁷ | on limit ☕

can i do this using an android phone?

Collapse
 
sunilaleti profile image
Sunil Aleti

no

Collapse
 
thisislexvt profile image
Carlos Alejandro

yes, use termux or another terminal emulator (and use nano as your text editor)

Collapse
 
adamooooo profile image
Adam • Edited

hello, i already had a dev account so i used that to make my app and it works, but i was wondering how i could use this same app to tweet on a different account. thanks!

Collapse
 
t0m0t0w profile image
t0m0t0w

where do i put where my label should be

Collapse
 
aksvins profile image
Aksvins

i think you cant? im just a beginner

Collapse
 
thisislexvt profile image
Carlos Alejandro

on the twitter dev dashboard (the app name is your label)

Collapse
 
thisislexvt profile image
Carlos Alejandro

on the twitter developers dashboard, the name of the app is your label

Collapse
 
sloveryp profile image
SloveryPort099

I did all the steps and I did what it said in the comment below me and it still doesn't work. Need Help.

Collapse
 
thisislexvt profile image
Carlos Alejandro

whats the error message?

Collapse
 
hamtarochyy profile image
ioowy

hello, what if I want to create a twitter thread? it seems like using the customized source label is only exclusive to 1 tweet???

Collapse
 
sunilaleti profile image
Sunil Aleti

You can

Collapse
 
mkcool142 profile image
MKCOOL142

How do I reply to other tweets or replies?

Collapse
 
sunilaleti profile image
Sunil Aleti

I mentioned the process in comments section.
Kindly check it

Collapse
 
mkcool142 profile image
MKCOOL142

import tweepy
auth = tweepy.OAuthHandler("Secret", "secret")
auth.set_access_token("secret", "Secret")
api = tweepy.API(auth)
reply = input(" ")
tweetId = input(" ")
api.update_status(reply, in_reply_to_status_id = tweetId, auto_populate_reply_metadata=True)
print ("Done!")

This is my solution

Thread Thread
 
arzikielt profile image
arzikiel tenebris • Edited

sorry i'm kinda retard,can you make an example?,(i don't know what's my mistake but it didn't work)

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more