0

Hello I just got into Twython. I'm trying to prevent my script from trying to retweet a Tweet multiple times (as this will raise an Error)

So I figgured out if you have a tweet the retweeted key should return wether you already retweeted that tweet.

However I wrote this Script:

def develop(twitter, keyword, count):
    global TweetIds, tweetInsert, FollowCounts
    results = twitter.search(q=keyword,count=count,result_type = 'popular')
    tweets = results['statuses']
    for tweet in tweets:
        if not tweet['retweeted']:
            try:
                twitter.retweet(id=tweet['id'])
            except TwythonError as e:
                print(e)

And this was the output

Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.
Twitter API returned a 403 (Forbidden), You have already retweeted this tweet.

So tweet['retweeted'] did return false even tough it should've been true.
What am I doing wrong?

seven_seas
  • 703
  • 4
  • 21

1 Answers1

0

The key 'retweeted' is used if you want to check if the tweet you are seeing is original or if it's retweeted. For example if I make a post and you check my post 'retweeted' is going to be False but if I retweet from someone else the value of 'retweeted' will be True.

What I've thought about preventing multiple retweets is to write the tweet id in a text file and check every time the file if you've already retweeted. I know this is not efficient at all but I am not sure about any other solution. To make it a bit faster you can create a new text everyday to minimize the number of ids you have run through to check. I hope I helped you

vmank
  • 773
  • 2
  • 7
  • 22