Sending out twitter retweets with Python
I wanted to know if this was possible- I want to use Python to retweet every tweet a person sends out. 开发者_JAVA百科If yes then how can I implement this?
Unfortunately, python-twitter does not yet support the Twitter Retweet REST call.
You'll have to make that call directly yourself (using direct calls to api._FetchURL) or apply the patch in issue 130 to add support.
You're better off with using tweepy; read the API documentation, there is a handy retweet(id)
method for retweeting.
Quick and dirty example:
import tweepy
auth = tweepy.BasicAuthHandler("username", "password")
api = tweepy.API(auth)
for status in api.user_timeline('someuser'):
api.retweet(status.id)
This will retweet the last 20 statuses from someuser
. You'll want to do some more coding to prevent it from retweeting those same messages again next time you run the script though.
Edit: Twitter no longer accepts BasicAuth authentication, and you'll have to use the OAuth authentication exchange to get a authorisation token. Changing the example above to use OAuth would detract from the retweet API point I was trying to make, see the Tweepy OAuth tutorial for an extensive tutorial.
It's possible to retweet anything the people you follow tweet.You can also retweet all of the public tweets.
Use this link : https://github.com/joshthecoder/tweepy you will know how to do it in a very simple way .
Here's the OAuth "Quick and dirty" method, please keep in mind that you will need to have Tweepy installed for this to work.
import tweepy
api_key = 'your_key'
api_secret = 'your_secret_key'
access_token = 'your_token'
access_secret = 'your_secret_token'
auth = tweepy.OAuthHandler(api_key, api_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
for status in api.user_timeline('someuser'):
api.retweet(status.id)
The newest version of python-twitter allows you to retweet with the command
api.PostRetweet(tweet_id)
where api is a logged-in api and tweet_id is the id of the tweet you want to retweet.
精彩评论