skip to Main Content

I made a Twitter Bot for retweeting, following and unfollowing people (when max reached), but when I thought that my bot was fully operational Twitter Blocked me.. That’s because if wansn’t checking if my bot already retweeted a tweet but I had a try/except block. So I was making a lot of api calls to retweet… I was wondering how I could check if I already retweeted this tweet ?
I thought of looking up every user of had retweeted the tweet and if my username was in it, passing to the next tweet, but it’s not very effective. I can share my code, and feel free to ask for any clarification.
Thank you,
Kajpio
PS: I’m using tweepy to interact with the API !

Update, here is a part of my code, just the part checking for retweet:

loginToTwitter()
query = 'a string'  
tweet_cursor= tweepy.Cursor(api.search, query, result_type="recent").items()
print("Searching")
for tweet in tweet_cursor:
    tweetText = tweet.text.lower()
    if "rt" in tweetText:
        if tweet.retweeted == True: #It return me each time a false boolean but then I get the api.code 327 from twitter 
            print("already retweeted")
            continue
        try:
            api.retweet(tweet.id)
            print('Retweedted')
            time.sleep(2)
        except tweepy.TweepError as e:
            if e.api_code == 327:
                print("Tried but tweet already Retweeted" )
            print(e)
            time.sleep(0.5)
            continue

2

Answers


  1. How many tweets are we talking about here? You could use an sqlite db to store the ID of tweets you have already retweeted. If there are too many tweets, you can clean the db of tweet IDs that you retweeted over 10 days ago or something, assuming you won’t find the same tweet after 10 days?

    Login or Signup to reply.
  2. You can check if you have already retweeted a particular tweet by keeping track of of the tweet’s id. Before you retweet, just check the tweet’s id against your list (or database table) of id’s. If the tweet your are retweeting is also a retweet of another tweet, you check that tweet’s id by looking at the retweet_status field.

    I don’t think you will get blocked by retweeting the same tweet multiple times. In general, Twitter will not let you tweet the same tweet more than once in a 24 hour period. Twitter will return error code 187 instead. (Twitter’s error codes.) You may have gotten blocked if you tweeted too frequently. Twitter doesn’t specify a rate limit for status updates. If you do exceed their internal rate limit, you will receive a 403 HTTP status code, and then it is up to you to back off from your updates until you no longer receive a 403 code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search