写一个脚本,将自动跟踪和RT帐户基于特定的关键字在Twitter上,但得到一个错误,当我试图跟踪一个美国

2024-04-25 05:56:49 发布

您现在位置:Python中文网/ 问答频道 /正文

如我所说,我正在尝试编写一个脚本,使用Tweepy-to-follow和基于一组关键字的RT帐户。该脚本可以很好地为RT工作,但在尝试执行时会抛出一个错误。你知道吗

File "twitterraffle.py", line 19, in <module>
    api.retweet(id)
  File "/usr/local/lib/python2.7/site-packages/tweepy/binder.py", line 245, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/site-packages/tweepy/binder.py", line 229, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{u'message': u'You have already retweeted this tweet.', u'code': 327}]
Jakes-MacBook-Pro:mystuff jakemills$ python twitterraffle.py
Traceback (most recent call last):
  File "twitterraffle.py", line 20, in <module>
    if ('following' in result):
TypeError: argument of type 'Status' is not iterable

如果我将for循环用于检查是否必须将帐户跟踪到一个单独的循环中,那么原来的循环可以正常工作。只是当我试着同时做的时候。你知道吗

我在下面附上了我的代码。你知道吗

提前谢谢。你知道吗

import tweepy

consumer_key = '***'
consumer_secret = '***'
access_token = '***'
access_token_secret = '***'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)


results = api.search(q="RT to win", lang="en")


i = 1

for result in results:
    if ('following' in result):
        user_id = result.user_id
        api.create_friendship(user_id)
        print 'Followed'

    id = result.id
    api.retweet(id)
    print "Retweeting %s" % i
    i = i + 1

Tags: inpytokenapiidsecretaccessconsumer