Birds also chirp other than tweet!!
RESTFUL APIs that retrieves tweets from twitter using Twitter API.
- Clone the repository
https://github.com/patrickian/Chirper.git
- Install python. this project requires
python 3.7.0
- Create a virtualenv. I recommend using
pyenv and pyenv-virtualenv
for controlling both your python version and your virtualenv. - Install
requirements.txt
by runningpip install -r requirements.txt
in the project directory.
- Signin your account in twitter. If you dont have an account, you can signup here.
- Apply for a twitter developer account. you can apply here.
- Once your application has been verified by twitter, you can now use the Twitter API!! Hoorayy :) please follow the instructions HERE on how to generate tokens to access Twitter API.
- Change directory inside the
chirper
folder and create your ownsecrets.json
by copying the content of thesecrets.json.template
. Please put your Twitter API keys here.
- run the migration.
python manage.py migrate
- run the server.
python manage.py runserver
NOTE: You can use limit
parameter to control the number of tweets to retrieve.
You can retrieve tweets by user using the following endpoint.
/user/<your_user_here>/
curl -H "Accept: application/json" -X GET http://localhost:xxxx/users/jdoe/?limit=20
Example response:
[
"favorites": 68,
"account": {
"fullname": "John Doe",
"url": "https://ti.co/onlysample",
"id": 123123123
},
"date": "Mon Sep 14 08:09:03 +0000 2019",
"text": "Sample tweet.SWEEEEEEET!!!!!",
"hashtags": [
"OneZeroOne"
],
"retweets": 40
...
]
You can retrieve tweets by hashtag by using the following endpoint.
/hashtags/<your_hashtag_here>/
curl -H "Accept: application/json" -X GET http://localhost:xxxx/hashtags/python/?limit=20
Example response:
[
"favorites": 96,
"account": {
"fullname": "Mary Jane",
"url": "https://ti.co/onlysample101",
"id": 687675547
},
"date": "Mon Sep 12 08:09:03 +0000 2019",
"text": "Python can kill you!!Programmatically and literally. oops :)",
"hashtags": [
"python"
],
"retweets": 19
...
]
You can run the following command to run unit tests: python manage.py test api.tests.TwitterTestCase