首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python-Twitter:检索最近提到的

Python-Twitter:检索最近提到的
EN

Stack Overflow用户
提问于 2014-08-12 22:42:46
回答 1查看 1.2K关注 0票数 0

我正在尝试使用Python库(https://github.com/bear/python-twitter)来使用GetMention()函数提取对twitter帐户的提及。脚本填充一个数据库,并定期运行在cron作业上,所以我不想每次提取这些内容,只有上次运行脚本时的那些。

下面的代码可以很好地提取提到,但出于某种原因,'since_id‘参数似乎什么也不做--这个函数每次运行它时都会返回所有提到的内容,而不是只过滤最近提到的内容。作为参考,文档在这里:https://python-twitter.googlecode.com/hg/doc/twitter.html#Api-GetMentions)

实现GetMention()函数的正确方法是什么?(我看过了,但在网上找不到任何例子)。或者,是否有一种不同的/更优雅的方法来提取我忽略的twitter提及呢?

代码语言:javascript
复制
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 ###
EN

回答 1

Stack Overflow用户

发布于 2014-08-12 23:45:00

正如Python库中提到的那样,您的语法似乎是一致的。我认为正在发生的情况如下:

如果Tweets的限制发生在since_id之后,则since_id将被迫使用可用的最老ID。

这将导致从最古老的可用ID开始的所有tweet。请尝试使用自ID值以来的最新消息。同样,也要检查您所提供的自定义ID是否合适。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25275288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档