1
最近我一直在玩tweepy,我試圖拉動追隨者和給定用戶的關注。tweepy中的循環錯誤
followingids = []
followids = []
userid = "Someone"#sets target
for page in tweepy.Cursor(api.followers_ids, screen_name=userid).pages():#gets the followers for userID
followingids.extend(page)
time.sleep(60)#keeps us cool with twitter
for page in tweepy.Cursor(api.friends_ids, screen_name=userid).pages():#gets the followers for userID
followids.extend(page)
time.sleep(60)#keeps us cool with twitter
#where weirdness starts
print len(followingids), "followers have been gathered from", userid
print len(followids), " users are followed by ", userid
followingusers = api.lookup_users(user_ids=followingids)#ieterates through the list of users and prints them
followedusers = api.lookup_users(user_ids=followids) #<does not work but above does
print "users of following", userid
for u in followingusers:
print u.screen_name
print "users followed by", userid
for s in followedusers:
print s.screen_name
for循環的第二打印給出了這樣的錯誤:
Traceback (most recent call last):
File "twitterBot.py", line 30, in <module>
followedusers = api.lookup_users(user_ids=followids) #<does not work but above does
File "/usr/local/lib/python2.7/dist-packages/tweepy/api.py", line 160, in lookup_users
return self._lookup_users(list_to_csv(user_ids), list_to_csv(screen_names))
File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 230, in _call
return method.execute()
File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 203, in execute
raise TweepError(error_msg, resp)
tweepy.error.TweepError: [{u'message': u'Too many terms specified in query.', u'code': 18}]
兩個followedusers和關注擁有Twitter ID號,我從字面上剪切和粘貼代碼打印那麼,爲什麼第一個工作和第二個不行?
你可以顯示生成下面的代碼和followids的代碼嗎? –
已添加,但代碼正常工作,因爲它應該將ID加載到列表中。 –