Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Twython返回tweet[';转发的';]的假值_Python_Twitter_Twython - Fatal编程技术网

Python Twython返回tweet[';转发的';]的假值

Python Twython返回tweet[';转发的';]的假值,python,twitter,twython,Python,Twitter,Twython,你好,我刚进入特威顿。我试图阻止我的脚本多次尝试转发Tweet(因为这会引发错误) 所以我想如果你有一条推文,retweeted键应该返回你是否已经转发了那条推文 但是我写了这个脚本: def develop(twitter, keyword, count): global TweetIds, tweetInsert, FollowCounts results = twitter.search(q=keyword,count=count,result_type = 'popula

你好,我刚进入特威顿。我试图阻止我的脚本多次尝试转发Tweet(因为这会引发错误)

所以我想如果你有一条推文,
retweeted
键应该返回你是否已经转发了那条推文

但是我写了这个脚本:

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)
这就是输出

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.
所以
tweet['retweeted']
确实返回了
false
即使是艰难的返回,也应该是
true


我做错了什么?

如果你想检查你看到的推特是原创还是被转发,可以使用
'retweeted'
键。例如,如果我发了一篇帖子,你检查我的帖子
'retweeted'
将为
False
,但如果我从其他人那里转发,
'retweeted'
的值将为
True

我所考虑的防止多次转发的方法是将tweet id写入文本文件,并在每次转发时检查该文件是否已转发。我知道这根本没有效率,但我不确定是否还有其他解决方案。为了使它更快一点,您可以每天创建一个新文本,以尽量减少您要检查的ID数量。我希望我能帮助你