Prerequisites
Before proceeding, ensure the following prerequisites are met:- Install MindsDB locally via Docker or use MindsDB Cloud.
- To connect Twitter to MindsDB, install the required dependencies following this instruction.
- Install or ensure access to Twitter.
Connection
To connect a Twitter account to MindsDB, you need a Twitter developer account.Please note that it requires a paid developer account.We recommend you use the Elevated access allowing you to pull 2m tweets and to avoid parameters or authentication issue error you might get sometimes. You can check this step-by-step guide describing how to apply for the Elevated access.
How to Apply for a Twitter Developer Account
How to Apply for a Twitter Developer Account
Begin here to apply for a Twitter developer accountWhen presented with questions under How will you use the Twitter API or Twitter Data?, use answers similar to the ones below (tweak to fit your exact use case). The more thorough your answers are, the more likely it is your account will get approved.Intended Usage (In Your Words)I have a blog and want to educate users how to use the Twitter API with MindsDB.I will read tweets that mention me and use them with MindsDB machine learning to generate responses. I plan to post tweets 2-3 times a day and keep using Twitter like I normally would.Are you planning to analyze Twitter data?I plan to build machine learning algorithms based on Twitter data. I am interested in doing sentiment analysis and topic analysis.I will potentially extract:
- Tweet text
- Favorite count and retweet count
- Hashtags and mentions
How to Generate API Keys
How to Generate API Keys
- Create an application with Read/Write permissions activated:
- Open developer portal.
- Select the
Add app
button to create a new app. - Select the
Create new
button. - Select
Production
and give it a name. - Copy and populate the following in the below
CREATE DATABASE
statement:Bearer Token
as a value of thebearer_token
parameter.API Key
as a value of theconsumer_key
parameter.API Key Secret
as a value of theconsumer_secret
parameter.
- Setup user authentication settings:
- Click
Setup
underUser authentication settings
: - On
Permissions
, selectRead and Write
. - On
Type of app
, selectWeb App
,Automated App or Bot
. - On
App info
, provide any URL for the callback URL and website URL (you can use the URL of this page). - Click
Save
.
- Click
- Generate access tokens:
- Once you are back in the app settings, click
Keys and Tokens
: - Generate
Access Token
andAccess Token Secret
and populate it in the belowCREATE DATABASE
statement:Access Token
as a value of theaccess_token
parameter.Access Token Secret
as a value of theaccess_token_secret
parameter.
- Once you are back in the app settings, click
Usage
Themy_twitter
database contains a table called tweets
by default.
Here is how to search tweets containing mindsdb
keyword:
Please note that we can see only recent tweets from the past seven days. The
created_at
column condition is skipped if the provided date is earlier than seven days.To learn more about native queries in MindsDB, visit our docs here.
For more information about available actions and development plans, visit this page.
Whatβs next?Check out the tutorial on how to create a Twitter chatbot to see one of the interesting applications of this integration.