Back to APIs list![stevekrouse avatar](https://images.clerk.dev/uploaded/img_2PqHa2Gsy93xQrjh2w78Xu0cChW.jpeg)
![andreterron avatar](https://avatars.githubusercontent.com/u/1753594?v=4)
![stevekrouse avatar](https://images.clerk.dev/uploaded/img_2PqHa2Gsy93xQrjh2w78Xu0cChW.jpeg)
Twitter API examples & templates
Use these vals as a playground to view and fork Twitter API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
![stevekrouse avatar](https://images.clerk.dev/uploaded/img_2PqHa2Gsy93xQrjh2w78Xu0cChW.jpeg)
twitterAlert
@stevekrouse
Cron
Twitter π keyword Alerts Custom notifications for when you, your company, or anything you care about is mentioned on Twitter. 1. Authentication You'll need a Twitter Bearer Token. Follow these instructions to get one. Unfortunately it costs $100 / month to have a Basic Twitter Developer account. If you subscribe to Val Town Pro, I can let you "borrow" my token. Just comment on this val and I'll hook you up. 2. Query Change the query variable for what you want to get notified for. You can use Twitter's search operators to customize your query, for some collection of keywords, filtering out others, and much more! 3. Notification Below I'm sending these mentions to a private channel in our company Discord, but you can customize that to whatever you want, @std/email, Slack, Telegram, whatever. TODO [x] ~Filter out retweets. We've long wanted to filter these out. Should be a quick fix if anyone wants to send me a PR :)~ Completed by @sumukh
twitter
@andreterron
Script
Login with ~~Twitter~~ π Use this val to login with π and save your token into a twitter_token val Usage Fork this val Change the π privacy to "Unlisted" Navigate to https://developer.twitter.com/en/portal/dashboard to create an OAuth app and save your client id and secret to your secrets page Navigate to https://{your_username}-twitter.web.val.run to authenticate with π And then you'll have your tokens saved to a twitter_token val! Other ~~Twitter~~ π helper vals Refresh your tokens: https://www.val.town/v/andreterron/refreshTwitterToken Fetch user by id: https://www.val.town/v/andreterron/fetchTwitterUser Search posts: https://www.val.town/v/andreterron/searchTweets Write an X post: https://www.val.town/v/andreterron/postTweet
![stevekrouse avatar](https://images.clerk.dev/uploaded/img_2PqHa2Gsy93xQrjh2w78Xu0cChW.jpeg)
populateTwitterDB
@stevekrouse
Script
Poll Twitter & Populate SQlite database The twitter API (or in this case someone else's wrapper over the twitter API) is finicky, so we just try to get one handle per minute, and shove whatever we get into our database, which could be an error message (this is why handles don't have a unique index).