Posting Twitter Retweets Using Python

I wanted to know if this was possible - I want to use Python to modify every tweet that a person sends. If so, how can I implement this?

+4
source share
4 answers

Unfortunately, python-twitter does not yet support Twitter Retweet REST call .

You will need to make this call directly (using direct calls to api._FetchURL) or apply the patch to question 130 to add support.

You better use tweepy ; read the API documentation ; there is a convenient 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 reassign the last 20 statuses from someuser . You will want to make some more codes to prevent the same messages from being replayed the next time you run the script.

Edit: Twitter will no longer accept BasicAuth authentication, and you will need to use OAuth authentication exchange to get the authorization token. Changing the example above to use OAuth will lead to a deviation from the point of the API repeater that I tried to do, see the Tweepy OAuth tutorial for an extensive tutorial.

+6
source

You can reconfigure everything that you follow on a tweet. You can also rephrase all public tweets.

Use this link: https://github.com/joshthecoder/tweepy you will know how to do this in a very simple way.

+3
source

Here's the OAuth "Quick and Dirty" method, please keep in mind that you will need to install Tweepy for this.

 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) 
+1
source

The newest version of python-twitter allows you to rephrase using the command

api.PostRetweet (tweet_id)

where api is the registered api and tweet_id is the id of the tweet you want to change.

0
source

Source: https://habr.com/ru/post/1345415/


All Articles