Question

I have a scenario in my django project where I need to retrieve all mentions of a specific twitter user. I have the credentials of the user. I have tried the search api which did not provide enough, I could not pull all mentions and also the limit set by twitter was hindering what I seek.

So, now I seek advice whether this can be achieved by the Streaming api or not? I also need to store the retrieved tweet details in my mongodb database so that I can run filter and custom searches. I am using twython package for this.

Was it helpful?

Solution

I'm not sure if you are trying to retrieve it from the authenticated user or not, but if you are this is what I came up with. Not sure if it's the best way or not though.

m = twitter.get_mentions_timeline(count=200)
    calls = 1
    id = m[-1]['id']
    next_id = -1

    # will continue calling mentions timeline until you hit rate limit
    # or there are no more mentions of authenticated user
    while id != next_id and calls < 16:
        temp = twitter.get_mentions_timeline(count=200,max_id=id)
        calls += 1
        next_id = temp[-1]['id']
        if id != next_id:
            m += temp
            next_id = -1
            id = temp[-1]['id']

m will be an array of all retrieved mentions of the authenticated user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top