Python Twitter:检索最近提到的内容
我试图使用pythontwitterlibrary()来使用getntity()函数提取对Twitter帐户的提及。该脚本填充数据库并定期在cron作业上运行,因此我不想提取每一个提及,只提取自上次运行脚本以来的提及 下面的代码可以很好地提取提到的内容,但出于某种原因,“since_id”参数似乎没有任何作用-该函数每次运行时都会返回所有提到的内容,而不是只过滤最近提到的内容。此处的文档仅供参考:) 实现getTitle()函数的正确方法是什么?(我已经看过了,但在网上找不到任何例子)。或者,是否有一种不同/更优雅的方式来提取我忽略的推特提及Python Twitter:检索最近提到的内容,python,twitter,python-twitter,Python,Twitter,Python Twitter,我试图使用pythontwitterlibrary()来使用getntity()函数提取对Twitter帐户的提及。该脚本填充数据库并定期在cron作业上运行,因此我不想提取每一个提及,只提取自上次运行脚本以来的提及 下面的代码可以很好地提取提到的内容,但出于某种原因,“since_id”参数似乎没有任何作用-该函数每次运行时都会返回所有提到的内容,而不是只过滤最近提到的内容。此处的文档仅供参考:) 实现getTitle()函数的正确方法是什么?(我已经看过了,但在网上找不到任何例子)。或者,是
def scan_timeline():
''' Scans the timeline and populates the database with the results '''
FN_NAME = "scan_timeline"
# Establish the api connection
api = twitter.Api(
consumer_key = "consumerkey",
consumer_secret = "consumersecret",
access_token_key = "accesskey",
access_token_secret = "accesssecret"
)
# Tweet ID of most recent mention from the last time the function was run
# (In actual code this is dynamic and extracted from a database)
since_id = 498404931028938752
# Retrieve all mentions created since the last scan of the timeline
length_of_response = 20
page_number = 0
while length_of_response == 20:
# Retreive most recent mentions
results = api.GetMentions(since_id,None,page_number)
### Additional code inserts the tweets into a database ###
您的语法似乎与Python Twitter库中提到的一致。我认为正在发生的情况如下: 如果Tweets的数量限制是在自\u id之后出现的,则自\u id将被强制使用最旧的可用id
这将导致所有推文从最旧的可用ID开始。请尝试使用较新的“自”ID值。同样,还要检查您提供的自ID是否合适。我确信我提供的ID是正确的-我在文档中看到了“Tweets的限制”,但不确定它指的是哪一个“限制”?(对api调用的限制?函数返回的tweet的限制?)奇怪的是,它似乎不起作用,不过感谢您的帮助!