TypeError:'Status'对象不可迭代

时间:2014-11-16 05:27:11

标签: python tweepy

运行此操作会向我显示错误TypeError: 'Status' object is not iterable

我试图从用户那里获取状态。

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 个答案:

答案 0 :(得分:1)

看起来是一个非常简单的修复:只需删除[1]部分,您就应该获得每条推文的ID。

for res in paginate(timeline, 50):
    for twet in res:
        print(twet.id)