就像我说的那样,我正在尝试使用Tweepy编写一个脚本来跟踪和基于一组关键字的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