Twitter sentiment analysis UbiOps¶
Download link for necessary files: Twitter sentiment analysis.
In this example we will show you the following: - How to connect with the Twitter API to collect tweets with a certain hashtag and predict the sentiment of. - How to display the sentiment of these tweets in a google sheets, that for example Tableau can use to read from.
Twitter sentiment analysis Deployment¶
The deployment is configured as follows:
|Function||A deployment that runs a sentiment analysis on tweets collected using the Twitter API and then stores it in Google sheets|
|Input field:||name: hastag, data_type: string|
|name: day, data_type: string|
|Output field:||emtpy because the results are written to the sheet|
|Description||Analyses tweets and pushes the results to Google sheets for further analysis|
How does it work?¶
Step 1: Login to your UbiOps account at https://app.ubiops.com/ and create an API token with project editor rights. To do so, click on Permissions in the navigation panel, and then click on API tokens. Click on [+]Add token to create a new token.
Give your new token a name, save the token in safe place and assign the following role to the token: project editor. This role can be assigned on project level.
step 2: Follow the next steps to get the necessary Twitter tokens and Google credentials: 1. Create a service user in Google. 2. Create credentials for the service user (called “keys” here). 3. Share the Google sheet with the Google service user account just like you would with a normal user: You hereby give it permission to edit your sheet. 4. A Twitter developer account and access to the Twitter API.
Step 3: Download the Twitter sentiment analysis folder and open
twitter_sentiment_analysis.ipynb. In the notebook you will find a space to enter your API token and the name of your project in UbiOps. Paste the saved API token in the notebook in the indicated spot and enter the name of the project in your UbiOps environment. This project name can be found in the top of your screen in the WebApp.
Step 4: Run the Jupyter notebook twitter_sentiment_analysis and everything will be automatically deployed to your UbiOps environment! Afterwards you can explore the code in the notebook or explore the application in the WebApp.