How to change Twitter Source Label
Sunil Aleti

Sunil Aleti @sunilaleti

About: Data Scientist

Location:
Dallas, TX
Joined:
Feb 24, 2020

How to change Twitter Source Label

Publish Date: Aug 13 '20
99 90

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 😊

Comments 90 total

  • Sunil Aleti
    Sunil AletiAug 14, 2020

    Thanks ☺️

  • Tomader910
    Tomader910Aug 15, 2020

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

    • Sunil Aleti
      Sunil AletiAug 15, 2020

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

      • Tomader910
        Tomader910Aug 15, 2020

        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)]

  • АнонимAug 15, 2020

    [hidden by post author]

    • Sunil Aleti
      Sunil AletiAug 15, 2020

      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.

      • Azka
        AzkaAug 15, 2020

        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!

      • Azka
        AzkaAug 15, 2020

        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?

        • Sunil Aleti
          Sunil AletiAug 15, 2020

          hav u changed to read & write ?

          • Azka
            AzkaAug 15, 2020

            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...

      • Shyam Raval
        Shyam RavalSep 12, 2020

        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 ?

  • АнонимAug 31, 2020

    [hidden by post author]

    • Sunil Aleti
      Sunil AletiSep 1, 2020

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

  • АнонимSep 5, 2020

    [hidden by post author]

  • Shyam Raval
    Shyam RavalSep 12, 2020

    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 ?

    • Sunil Aleti
      Sunil AletiSep 21, 2020

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

    • Aksvins
      AksvinsMar 25, 2021

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

  • Harsh #34
    Harsh #34Sep 22, 2020

    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?

    • Sunil Aleti
      Sunil AletiSep 22, 2020

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

      • Harsh #34
        Harsh #34Sep 22, 2020

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

        • Sunil Aleti
          Sunil AletiSep 22, 2020

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

      • arzikiel tenebris
        arzikiel tenebrisDec 31, 2020

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

  • Sunil Aleti
    Sunil AletiSep 26, 2020

    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
    • Edgar
      EdgarNov 26, 2020

      where do i put the image path

      • Sunil Aleti
        Sunil AletiNov 26, 2020

        In 5th line, inside input enter the image location

        • Edgar
          EdgarNov 26, 2020

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

    • nonvieri
      nonvieriJan 23, 2021

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

  • zayn’s refrigerator
    zayn’s refrigeratorOct 10, 2020

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

  • ja⁷ | on limit ☕
    ja⁷ | on limit ☕Nov 26, 2020

    can i do this using an android phone?

  • Adam
    AdamNov 28, 2020

    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!

  • t0m0t0w
    t0m0t0wDec 2, 2020

    where do i put where my label should be

    • Aksvins
      AksvinsMar 25, 2021

      i think you cant? im just a beginner

    • Carlos Alejandro
      Carlos AlejandroJun 12, 2021

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

    • Carlos Alejandro
      Carlos AlejandroJun 12, 2021

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

  • SloveryPort099
    SloveryPort099Dec 4, 2020

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

  • ioowy
    ioowyDec 16, 2020

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

  • MKCOOL142
    MKCOOL142Dec 22, 2020

    How do I reply to other tweets or replies?

    • Sunil Aleti
      Sunil AletiDec 24, 2020

      I mentioned the process in comments section.
      Kindly check it

      • MKCOOL142
        MKCOOL142Dec 24, 2020

        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

        • arzikiel tenebris
          arzikiel tenebrisJan 4, 2021

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

  • Jenaux
    JenauxJan 2, 2021

    Hi, can you show me an example on how to reply a specific or how to set the code with an image, Im sorry Im a bit confused and tried many times

  • end sportybet before it ends you
    end sportybet before it ends youJan 14, 2021

    is there a way i can tweet from an account different from the one i used to register as a developer?

  • nonvieri
    nonvieriJan 19, 2021

    what is the code to add geolocation to a tweet?

  • amir bro⚜️
    amir bro⚜️Feb 7, 2021

    But as the last step when I open the .py file and write something and hit enter, it doesn't get tweeted! How can I solve this?

  • 🌹 lovestay 🌹 every race deserved to be respected
    🌹 lovestay 🌹 every race deserved to be respectedMar 18, 2021

    someone on twitter send this cuz his device name is i miss hyunjin , pls i want to do that too ;-;

  • Aksvins
    AksvinsMar 25, 2021

    If I want to do it for another source label, then how would I do it? I already made one, now I want to use it for a new one. So how would I do it? I'm pretty new to coding so that's why.

    • Aksvins
      AksvinsMar 25, 2021

      oh wait i got it, just need to change the keys.

    • Carlos Alejandro
      Carlos AlejandroJun 12, 2021

      you will have to make another twitter app, or change the name of the app in the twitter dev dashboard

  • Pink Lemons
    Pink LemonsJun 25, 2021

    This is my dilemma... I truly don't understand why it becomes a "PY file" under type of file when all the tutorials and guides show that after putting ".py" to the file name and saving under "All Files", it becomes that instead of how it should be. Is the problem my laptop and its system instead? Or... I feel lost.

  • Pink Lemons
    Pink LemonsJun 25, 2021

    I truly don't understand why mine becomes a "PY file" under type of file when all the tutorials and guides show that after putting ".py" to the file name and saving under "All Files", it should be "Python File", but it becomes that instead of how it should be. Is the problem my laptop and its system instead? Or... I feel lost.

  • Nand0
    Nand0Jul 15, 2021

    How to post a tweet with "new line" \n didn't work

  • Nathan
    NathanAug 12, 2021

    can i add emoji to the tweet?

  • Puyi
    PuyiJan 1, 2022

    How do u fix this error

    i first do all the cd path and pip install tweepy
    where i come to the commend python -i testla.py
    C:\Users\cat\AppData\Local\Programs\Python\Python37-32\Scripts>python -i testla.py

    and after that it just stays black screened so i just input something in the cmd where this error show up afterwards:

    Traceback (most recent call last):
    File "testla.py", line 6, in
    api.update_status(status =(tweet))
    File "C:\Users\cat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tweepy\api.py", line 46, in wrapper
    return method(*args, **kwargs)
    File "C:\Users\cat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tweepy\api.py", line 1128, in update_status
    ), status=status, **kwargs
    File "C:\Users\cat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tweepy\api.py", line 257, in request
    raise Unauthorized(resp)
    tweepy.errors.Unauthorized: 401 Unauthorized
    32 - Could not authenticate you.

    • Puyi
      PuyiJan 2, 2022

      So update the problem i have i tried some other things and used Authentication to connect the app to my other account, because the one i wanna use the bot is. Didn't get accepted into twitter twitter developer. So I'm trying to make it so the account i have a twitter developer for, makes the app but so i can allow any other account to use it.

      How do i get the consumer key or should i write something else into the code, to tweet from another account.
      Because the code itself is working if i do it the account that have access to it's own consumer key and that, but how do u authorized your app so others can use it, and where do u put that code you get from the url i have a url with the account i allowed the app on that have two numbers in it
      Oauth_token & auth_verifier so i'm asking how do i use another user consumer key when u can't access twitter developer on that account?

      • Puyi
        PuyiJan 2, 2022

        TLTR
        Posting on behalf of a user since the account i wanna use my app with that have access to twitter developer. Do i need to change the code or something? since i don't have consumer key and that for the twitter account that i wanna tweet from

  • Tristan
    TristanJan 7, 2022

    What version of python should I download?

  • Babu Okiru 🇰🇪
    Babu Okiru 🇰🇪Feb 13, 2022

    Is python an app?

  • Dubey_Chandan
    Dubey_ChandanMar 7, 2022

    i did everything same but getting error can you please help me?

    C:\Users\PCofDC\AppData\Local\Programs\Python\Python310\Scripts>python -i tweeter.py
    ok done
    Traceback (most recent call last):
    File "C:\Users\PCofDC\AppData\Local\Programs\Python\Python310\Scripts\tweeter.py", line 6, in
    api.update_status(status =(tweet))
    File "C:\Users\PCofDC\AppData\Local\Programs\Python\Python310\lib\site-packages\tweepy\api.py", line 46, in wrapper
    return method(*args, **kwargs)
    File "C:\Users\PCofDC\AppData\Local\Programs\Python\Python310\lib\site-packages\tweepy\api.py", line 1121, in update_status
    return self.request(
    File "C:\Users\PCofDC\AppData\Local\Programs\Python\Python310\lib\site-packages\tweepy\api.py", line 259, in request
    raise Forbidden(resp)
    tweepy.errors.Forbidden: 403 Forbidden
    453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: developer.twitter.com/en/docs/twit...


    • Lyton
      LytonApr 20, 2022

      Turns out we have to use the v2 of the API, and the instructions are different

  • πie
    πieMar 12, 2022

    Tweeted an image and the image address got tweeted as text with together the image


    C:\Users\Lowe\Downloads\Test.PNG pic.twitter.com/rA8ou0AuIx

    — πie (@pumpkinpie0_) March 12, 2022
  • X5 Gamer Yee & Shreky
    X5 Gamer Yee & ShrekyApr 3, 2022

    How can I fix this?
    File "C:\Users\X5 Gamer Yee\AppData\Local\Programs\Python\Python310\Scripts\e_reply.py", line 6, in
    api.update_status(tweet, in_reply_to_status_id = twitter.com/X5GamerYee/status/1510723282563174401)
    NameError: name 'twitter' is not defined

  • Harsh #34
    Harsh #34Jun 2, 2022

    Hey, so since twitter has upgraded it's Authentication process to OAuth 2.0 do we have to do anyhtinbg different? because I tried everything and it doesn't work

  • 🏳️‍⚧️𝗙𝗲𝗿𝗻🏳️‍🌈
    🏳️‍⚧️𝗙𝗲𝗿𝗻🏳️‍🌈Jul 7, 2022

    I did everything it told me to do but the python script said it needs elevated access so I applied for elevated access and was rejected, what do I do

  • ayadi
    ayadiOct 8, 2023

    it says tweepy needs to be installed i already installed it 3 times now

  • ayadi
    ayadiOct 8, 2023

    Image description

Add comment