Skip to content

This API is for fetching and storing the target tweets with metadata

License

Notifications You must be signed in to change notification settings

nikhilbisht21/Twitter-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter-API

This API is for fetching and storing the target tweets with metadata

Twitter Search/Streaming API

Objectives

  • 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

Basic structure diagram of API

Specifications

Programming language : Python

Database : MongoDB(NoSQL Database)

Data fetching method : Searching and Streaming

Prerequisite

Python modules

  • python-twitter
  • pymongo

Twitter authetication keys

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

MongoDB

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.

API Functions

  • configure()
  • exportFilter()
  • exportToCSV()
  • filterDateTime()
  • filterTweets()
  • initialize()
  • search()
  • searchTweets()
  • sortTweets()
  • streamTweets()
  • tweetBook_object.next()
  • tweetBook_object.previous()
  • verify()
  • viewBook()

Getting Started

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)

Now api is ready to be use. For further details check documentation and references.

References

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

About

This API is for fetching and storing the target tweets with metadata

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published