Search code examples
pythontwitterpython-twitter

Programmatic retweeting with Python's twitter library


I'm trying to programmatically retweet various tweets with Python's python-twitter library. The code executes without error, but the RT never happens. Here's the code:

from twitter import Twitter, OAuth

# my actual keys are here
OAUTH_TOKEN = ""
OAUTH_SECRET = ""
CONSUMER_KEY = ""
CONSUMER_SECRET = ""

t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
        CONSUMER_KEY, CONSUMER_SECRET))

result = t.statuses.retweets._id(_id=444320020122722304)

print(result)

The only output is an empty list. How can I get it to actually RT the tweet?


Solution

  • All of the answers posted here were instrumental in finding the final code that works. Thank you all! The code that works with the python-twitter library is below.

    from twitter import Twitter, OAuth
    
    # my actual keys are here
    OAUTH_TOKEN = ""
    OAUTH_SECRET = ""
    CONSUMER_KEY = ""
    CONSUMER_SECRET = ""
    
    t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
            CONSUMER_KEY, CONSUMER_SECRET))
    
    result = t.statuses.retweet(id=444320020122722304)
    
    print(result)