pythontwittertweepytwitter-streaming-api

Retrieving tweet by tweet-id


Is it possible to stream tweets for a list of tweet-ids using tweepy or twython? I am trying to use to Twython using tweets = t.lookup_status(id=Id)

'Id' looping over a list of tweet-ids

but there are rate limitations I guess and in case of tweepy, using StreamListener, I can only get tweets for some particular track. In my case, I have a list of tweet_ids for which I need the tweet-text, created_at, source, url etc ... Or is there any other option for this task? I am quite new to this. Please excuse if the question is naive!


Solution

  • I'm not quite clear what it is you're after, but you can find tweets that match a certain tweet id using the following snippet (provided you have a consumer_key, consumer_secret, access_token, and access_token_secret from the Twitter API):

        import tweepy
    
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
    
        api = tweepy.API(auth)
    
        public_tweets = api.home_timeline()
    
        good_tweet_ids = [555175389383774208, 555174725136437248]
    
        for tweet in public_tweets:
            if tweet.id in good_tweet_ids:
                print "".join(x for x in tweet.text if ord(x) < 128)