Steps to import Twitter data to Google Sheets:
Step 1: Install Amigo Data add-on
Step 2: Get the API key and secret, and bearer token
Step 3: Choose the endpoint
Step 4: Import the data
Twitter lets developers pull several types of data from its platform such as users information like followers list, following list, tweets timeline, tweet information; trending topics–globally, or by countries and regions; and also information that are not publicly available such as tweets impressions, and other metrics.
You don’t need to be a developer, however, for importing Twitter information to Google Sheets as you can easily import them using Amigo Data–a Google Sheets extension.
So, let us learn step by step how to import Twitter data to Google Sheets.
How to import Twitter data to Google Sheets
Step 1: Install the Amigo Data add-on
Install the Amigo Data Google Sheets add-on from the Google Workspace Marketplace. Click here.
Alternatively, you can get it from Google Sheets itself.
- Open a new sheet
- Go to Extensions→Add-ons→Get add-ons
- Search for Amigo Data and install
Step 2: Get the Twitter API key and secret, and bearer token
In order to make API requests, we need to create an app on Twitter’s developer platform which will make the request on behalf of the user.
Follow the steps given below to create an app and generate a bearer token and other keys.
Go to Twitter’s Developer Platform and sign in using your Twitter account (or sign up if you don’t already have one).
After you’ve signed in (or up), click Developer Portal.
On the next page, you’ll be asked to enter certain details. After filling those fields and accepting the Developer Agreement and confirming your email, you’ll be redirected to the developer portal with a welcome message.
Give the app a name and click Get keys. The API key, API key secret, and Bearer token will be generated immediately. Copy those to a safe and confidential location.
Having gotten the keys and the token, we can proceed to pulling data from Twitter to Google Sheets.
Step 3: Choose a data endpoint
All data have an endpoint URL which points to that particular dataset. There are several ways to get the endpoint URL. We’ll use a simple and interactive one.
From the previous page (where the keys was displayed) click the API playground button. You can also click this link to go to that page or click on Go to API playground from the Developer Portal dashboard.
On the playground page, search for the data sets you want to import using the search bar.
As an example, let us import Elon Musk’s tweets timeline. So we can simply search “timeline”.
Select GET /2/users/:id/tweets
There are some parameters to be filled some of which are mandatory.
The user ID can be got from here. Just enter the Twitter handle and it will give the ID of that user.
Copy the ID and paste it in the id field.
The since_id is the ID of the tweet from which the timeline begins, ie, from that tweet onwards.
The tweet ID can be found by opening the particular tweet. The numbers following status in the tweet URL is the tweet ID.
For example, below is one of Musk’s tweets. The numbers 156…8 is the tweet ID. https://twitter.com/elonmusk/status/1564993132873146368
Fill in the other parameters and fields if you want (they’re not mandatory) and click Run.
Then on the next page, click Authorize app.
You’ll see the response on the screen.
Click the three dots just above the top right corner of the response field to see the details of the response.
The endpoint URL can be found under cURL. Copy that without including the quotation marks.
You can also get the endpoints using the Twitter API tools. The process is more or less the same as the one just covered here.
Step 4: Import the data from Twitter to Google Sheets
Now that we’ve got all the materials we need, we can begin to import Twitter data to Google Sheets. Follow the steps below to import the data using Amigo Data.
- Launch the Amigo Data extension from Google Sheets
- From the list of sources, select Custom API.
- Paste the endpoint URL in the API URL bar.
- Then expand the Details tab and enter the following as a header.
Name: Authorization, Value: Bearer your_token
- Click PREVIEW and then flatten the data sets
- Finally click the IMPORT button
The Twitter data will be imported to Google Sheets in a moment. Below is a snippet of the imported data.
And so that’s how we import Twitter data to Google Sheets. We don’t even have to log in to Twitter to read tweets as the data will be automatically updated and refreshed.
For more endpoints and details on Twitter API, you can check out Twitter API documentation.
Setting refresh schedule
To get the information updated periodically, click the report, toggle on the Refresh Schedule and select the schedule–hourly, daily, weekly or custom days.
Then click Save & Run.
Alerts via email or Slack
You can get the report sent to your email or a Slack channel so that you do not even have to open the spreadsheet to keep track of what’s happening or being tweeted.
To set up an alert, click Get Alerts→Add alert data+. Edit the details and click Set Alert.
It becomes an easy process to integrate Twitter data to Google Sheets–once the first procedure has been completed. And then we can watch and read tweets from a distance without getting into the mess that Twitter is, or get the trends and other metrics into Google Sheets.
There are several other types of data that you can import to Google Sheets using Amigo Data. A few examples are stock data from Yahoo Finance, cryptocurrency prices and market capitalisation, US patent information, and Wikipedia.
For these and many more, visit our blog.
Some similar articles you may find interesting: