This API is for fetching and storing the target tweets with metadata
- Trigger a twitter search/stream for recent high traffic events.
- Return stored tweets and their metadata based on applied filters/search.
- Export data to csv file
- python-twitter
- pymongo
In order to fetch the data from twitter we have to send a connection request to twitter servers with header. This header contains authetication parameters which are basically authetication tokens provided by twitter. Following keys are needed in order to use the api:
- consumer_key
- access_token_key
- consumer_secret
- access_token_secret
There are two ways to work on mongoDB, either it could be installed directly in our local system or use the free cloud database service.A URI is needed in case free cloud database is used.
See resources for further details.
- configure()
- exportFilter()
- exportToCSV()
- filterDateTime()
- filterTweets()
- initialize()
- search()
- searchTweets()
- sortTweets()
- streamTweets()
- tweetBook_object.next()
- tweetBook_object.previous()
- verify()
- viewBook()
1. Import Twitter-API as tap
2. tap.configure(consumer_key='consumer_key',access_token_key='access_token_key',tap.consumer_secret='consumer_secret',
tap.access_token_secret='access_token_secret',uri='uri')
Note: Leave uri blank in case you are running mongoBD on your local system, and ensure that the mongoDB server is started on your local system before initializing the API.
3. tap.initialize()
4. tap.searchTweets(keywords=['modi','AbkiBarModiSarkar','ModiForPM'],deliminiter='or',count=1000)
OR tap.streamTweets(keywords=['modi','AbkiBarModiSarkar','ModiForPM'],deliminiter='or',count=1000)
Standard Searching https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
Stream Filtering https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters
Introduction to Tweet JSON https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/intro-to-tweet-json
Tweet data dictionaries https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/tweet-object
Link to get application tokens https://apps.twitter.com/
Guide to get application tokens https://github.com/bear/python-twitter/blob/master/doc/getting_started.rst
Link to the guide to get URI https://docs.mongodb.com/manual/tutorial/atlas-free-tier-setup/
Download link to monogoBD https://www.mongodb.com/download-center