I want user’s tweet data whenever they tweet new. But without running script every 15 minutes to know whether they have new tweet or new. It takes lots of resources. Is there any way that I will get data only when they tweet?
Question posted in Twitter API
The official Twitter API documentation can be found here.
The official Twitter API documentation can be found here.
2
Answers
Twitter has a webhook API that you can hook into.
https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/subscribe-account-activity/guides/getting-started-with-webhooks
Essentially,
Register your application on Twitter Developer platform.
Create an API endpoint on your Django application that will accept this request when Twitter sends it to you.
Submit that API endpoint in your deployed app to the Twitter application that you created in step 1.
Do what you want with the request.
That being said, Twitter’s API has been locked down considerably so applying for a developer account may take a while.
I’d recommend taking a look at the filtered stream API. Assuming the account is not protected, you can use the
from:
operator to receive Tweets in real-time whenever the user Tweets something new.