0
votes

I am trying to make an application for an organization which will required to fetch all past as well present tweets with some particular hashtag like #airtel, @airtel etc, how should I get past tweet, I am able to fetch the present tweet with the following url : "https://api.twitter.com/1.1/search/tweets.json?q=%23airtel"

Thanks

2

2 Answers

0
votes

You can get up to a maximum of 100 tweets with the twitter rest api see the following twitter documentation. The best you can do is use the count parameter https://api.twitter.com/1.1/search/tweets.json?q=%23airtel&count=100

0
votes

After various search on Google I found some useful library for fetching tweets e.g:

TwitterSearch [https://github.com/ckoepp/TwitterSearch], you would I find the twitter profile @ https://twitter.com/twittersearch

Tweepy [https://github.com/tweepy/tweepy], you could find more info at http://www.tweepy.org/

I have implemented using both. Tweepy implementation is as follows:

import tweepy
import json

consumer_key = "get"
consumer_secret = "From"
access_token = "Twitter"
access_token_secret = "site"
# Authenticate twitter Api
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
#made a cursor
c = tweepy.Cursor(api.search, q='%23Coursera')
c.pages(15) # you can change it make get tweets

#Lets save the selected part of the tweets inot json
tweetJson = []
for tweet in c.items():
    if tweet.lang == 'en':
        createdAt = str(tweet.created_at)
        authorCreatedAt = str(tweet.author.created_at)
        tweetJson.append(
          {'tweetText':tweet.text,

          'tweetCreatedAt':createdAt,
          'authorName': tweet.author.name,
          })
#dump the data into json format
print json.dumps(tweetJson)

If any one have problem, let me know, will provide git repo for this.

Thanks Krishna