问题
Running this gives me the error TypeError: 'Status' object is not iterable
I'm trying to get the statuses from the user.
import simplejson
import httplib2
import tweepy
import random
import time
import itertools
def paginate(iterable, page_size):
while True:
i1, i2 = itertools.tee(iterable)
iterable, page = (itertools.islice(i1, page_size, None),
list(itertools.islice(i2, page_size)))
if len(page) == 0:
break
yield page
auth = tweepy.OAuthHandler("removed", "removed")
auth.set_access_token("removed", "removed")
api = tweepy.API(auth)
timeline = api.user_timeline("removed")
for res in paginate(timeline, 50):
for twet in res[1]:
print(twet.id)
回答1:
Looks like a pretty simple fix: Just remove the [1]
part, and you should get the ID for each tweet.
for res in paginate(timeline, 50):
for twet in res:
print(twet.id)
来源:https://stackoverflow.com/questions/26954107/typeerror-status-object-is-not-iterable