0

我正在尝试使用 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 ###
4

1 回答 1

0

您的语法似乎与 Python-Twitter 库中提到的一致。我认为正在发生的事情如下:

如果自 since_id 以来已发生 Tweets 限制,则 since_id 将被强制为可用的最旧 ID。

这将导致所有推文从最旧的可用 ID 开始。尝试使用更新后的 ID 值。同样,还要检查您提供的自 ID 是否合适。

于 2014-08-12T23:45:00.927 回答