TypeError:“状态”对象不可迭代-Python Twitter搜索

时间:2018-11-17 00:36:06

标签: python json

我正在尝试编写嵌套在输出中的两个文件json:

第一个可以,我可以看到整个结构(我更喜欢先保存完整的json),但是在第二个中,当我尝试过滤某些json的字段时,我遇到了以下问题-

  

返回码错误“ TypeError:'状态'对象不可迭代”。

如何在第二个输出中使用经过过滤的结构(tweet.created_at", "tweet.id", "tweet.user.followers_count", "tweet.user.friends_count", "tweet.retweet_count", "tweet.favorite_count", "tweet.text)

for query in ["BNL","BNPP"]:
    with open('/Users/davide/Documents/Personale/Python/output_json.json', 'w') as outfile:
        for tweet in tweepy.Cursor(api.search,q=query,
                               count=2,
                               lang="it",
                               since="2018-11-03").items(max_tweets):
            json.dump(tweet._json, outfile, indent=2) 
            outfile.write('\n')

                  #start filtered step json

            with open('/Users/davide/Documents/Personale/Python/output_json_filtered.json', 'w') as outfile2:
                filtered_keys = ["tweet.created_at", "tweet.id", "tweet.user.followers_count", "tweet.user.friends_count", "tweet.retweet_count", "tweet.favorite_count", "tweet.text"]
                for filtered_keys in tweet:
                    json.dump(filtered_keys._json, outfile2, indent=2) 
                    outfile2.write('\n')  

预先感谢

0 个答案:

没有答案