如何在Tweepy中获取推特ID

问题描述

我想搜索一个关键字并获得70条推文,然后列出所有推文的ID。我不知道如何,请帮忙。

import tweepy
import time

auth = tweepy.OAuthHandler('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxxx')
auth.set_access_token('xxxxxxxxxxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxxxx')

api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
user = api.me()



import time

time_limit_sec = 600
start_time = time.time()



for tweet in tweepy.Cursor(api.search,q="books",result_type="recent").items(70):  
    status = api.get_status(id) 
    id = status.id 
    print("The ID of the status is :"  + str(id)) 
    break

解决方法

tweet ID在_json ['id']下。请勿使用 break ,当您设置项目(70)时,它将限制为70。

for tweet in tweepy.Cursor(api.search,q="books",result_type="recent").items(70):  
    print("The tweet id is:",tweet._json['id'])

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...