微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tweepy 跳过以前喜欢的推文,同时喜欢新的提及

如何解决Tweepy 跳过以前喜欢的推文,同时喜欢新的提及

我之前看过这个问题,但没有答案。我有一个功能喜欢(收藏)最近提到我的用户的推文。我检查状态的收藏属性以过滤掉我已经收藏的那些,但我收到错误,我已经收藏它们,即使该属性返回了一个 false 布尔值。

这是我的代码

def like_mentions(str_state):
    api = get_tweepy_api(getcreds(twitter_accounts[str_state]))
    query = '@' + twitter_accounts[str_state]
    for tweet in tweepy.Cursor(api.search,q=query,lang='en').items(5):
        try:
            # Add \n escape character to print() to organize tweets
            print('\nTweet by: @' + tweet.user.screen_name)
            # like tweets that mention me
            print("This was favorited? " + str(tweet.favorited))
            if not tweet.favorited:
                tweet.favorite()

        except tweepy.TweepError as e:
            print(e.reason)

        except stopiteration:
            break

对于查询中的每个返回状态,我收到以下错误

Tweet by: @Bob_Mayo
This was favorited? False
[{u'message': u'You have already favorited this status.',u'code': 139}]

Tweet by: @Mark56744423
This was favorited? False
[{u'message': u'You have already favorited this status.',u'code': 139}]

知道我在这里做错了什么吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。