【问题标题】:Is there any direct way/method to verify whether a Tweet exists or not?是否有任何直接的方式/方法来验证推文是否存在?
【发布时间】:2020-11-17 06:37:28
【问题描述】:

如果存在推文,我需要一个仅返回 True 的方法,否则返回 False 而不使用 statuses_look() 或 try-except,因为我不希望它首先获取所有数据看看是否存在。

例如:我想要达到的目标:

id = '1287710013964931072'
if api.is_valid_status_id(id): #build-in method or simply creating my own function.
    process_data(id)

但不像……

id = '1287710013964931072'
try :
    status = api.get_status(id)
    process_data(id)
except:
    pass

id = ['1287710013964931072']
for status in api.statuses_lookup(id):
    process_data(id)

【问题讨论】:

    标签: python api twitter tweepy twython


    【解决方案1】:

    不,有效的 ID 不一定与 Twitter 上的推文相对应,如果不进行检查,就无法知道它是否对应。直接的方法是向 Twitter 的 API 发出请求以确定 ID 是否代表现有的推文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 2018-06-17
      • 2010-09-15
      • 2012-08-08
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      相关资源
      最近更新 更多