我正在尝试使用 Python-Twitter 库 ( https://github.com/bear/python-twitter ) 使用 GetMention() 函数提取 Twitter 帐户的提及。该脚本填充数据库并定期在 cron 作业上运行,因此我不想提取每一个提及,只提取自上次运行脚本以来的那些。
下面的代码很好地提取了提及,但由于某种原因,“since_id”参数似乎没有做任何事情 - 该函数每次运行时都会返回所有提及,而不是仅过滤最近的提及。供参考的文档在这里:https ://python-twitter.googlecode.com/hg/doc/twitter.html#Api-GetMentions )
实现 GetMention() 函数的正确方法是什么?(我看过,但我在网上找不到任何例子)。或者,是否有一种不同/更优雅的方式来提取我忽略的 twitter 提及?
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 ###