Next, you’ll need to define the following environment variables. You can use your shell or create a .env file in the root directory of the project and add the following into it, making sure to not include the angle brackets themselves.
TW_TERM=<A keyword you are interested in>
TW_HASHTAG=<A hashtag you are interested in>
TW_GOOGLE_DOC_ID=<The id of the Google Sheet to store the tweets in>
The code creates a filter rule that uses TW_TERM and TW_HASHTAG to filter the stream. It creates a rule to capture only Tweets that have the keyword or the hashtag variables in them. So for example, if you entered the following...
By entering this keyword and hashtag into the environmental variable, you will be adding the following rule to your stream: Tennis OR #Wimbledon
The Google Sheet id is the last part of the Sheet’s URL:
You will also need to store the JSON key file you downloaded from Google in the root directory of the project. Make sure it is named client_secret.json.
Once you have done this, you can run the code and it should work - depending on the search term and hashtag you set, Tweets should start appearing in your spreadsheet.
If the code doesn’t work, it is most likely that something was misconfigured. For example - the TW_TERM or TW_HASHTAG were not defined in the environment.
If that happens, your first step is to check the console output,where the code logs notify you of any such issues.
If Tweets do not appear in your spreadsheet,it might be that your filter is too restrictive. Use the details in the walkthrough below to fine-tune it.
The remainder of this guide walks you through the code to explain what it does and how you can use these concepts in your own code.