Hey fellow dashdashers
You want to know the followers of a specific Twitter account? Or want to know who is following whom? We will soon build a Twitter integration for this. In the meantime, for the technically savvy among you, this easy guide will show in just 5 steps:
- Apply for a Twitter developer account
- Get your authentication token
- Build your authentication header
- GET & PARSE for user_ids of followers
- Transcribe user_ids into screen_names
Apply for a Twitter developer account
This step is easy. Navigate to Twitter’s developer page and set yourself up with a developer account
If you are asked to create an app in the process, please go ahead and do so. Just fill in required fields.
Get your authentication token
Here the authentication process get’s a bit trickier. But bear with me, I’ll guide you through the setup
First, go to your newly created Twitter app. Click on Details and then Keys and tokens. Fetch your Consumer API keys (key and secret); you’ll need them in a second.
Next, go into dashdash, create a new app and rename View1 into Control. And now, copy the function below in the correct cells, whereas A2
and B2
are your API key and API secret key respectively.
A1 = API key B1 = API secret key
A2 = 888BjbRn... B2 = vTiuz6iwKj1f8...
A4 = concatenate B4 = CONCATENATE(A2,":",B2)
A5 = base64 B5 = BASE64(B4)
A6 = POST header 1.1 B6 = Authorization
A7 = POST header 1.2 B7 = CONCATENATE("Basic ",B5)
A8 = POST header 2.1 B8 = Content-Type
A9 = POST header 2.2 B9 = application/x-www-form-urlencoded;charset=UTF-8
A10 = pair2json B10 = PAIR2JSON(B6,B7,B8,B9)
A11 = body B11 = grant_type=client_credentials
A12 = POST B12 = POST("https://api.twitter.com/oauth2/token?"&B11&"",B10,"{}")
We basically re-packaged our API key/secret key and send it back to the API with some mandatory parameters. In response, we get our authentication token in B12
Your view should look as follows:
Build your authentication header
Now that we got our authentication token, we can start building our GET request. However, in preparation we need to put together our authentication headers for the request (columns D
and E
in the above screenshot). And this is how you do it
D1 = PARSE(B12,"['token_type']")
D2 = PARSE(B12,"['access_token']")
D4 = GET header 1.2 E4 = Authorization
D5 = GET header 1.2 E5 = CONCATENATE(D1," ",D2)
D6 = pair2json E6 = PAIR2JSON(E4,E5)
Amazing, your authentication header is ready and locked to go in E6
GET & PARSE for user_ids of followers
Now, let’s continue by building our GET request to get followers! First, create a new view and name it Followers. Then, decide which API endpoint to use:
Accounts followed by screen_name = https://api.twitter.com/1.1/friends/ids.json?screen_name=[name]
Accounts following screen_name = https://api.twitter.com/1.1/followers/ids.json?screen_name=[name]
Once you’ve settled down on your endpoint, finally build the GET request and insert the User IDs into column A:
A1 = screen_name B1 = dashdash
A2 = GET request_1 B2 = GET("https://api.twitter.com/1.1/friends/ids.json?screen_name="&B1&"",'Control'!E6)
A3 = PARSE IDs B3 = PARSE(B2,"['ids']")
A5 = IDs
A4 = Insert B4 = INSERT_DATA(B3,A5)
Now all user IDs automatically get inserted into column A6:A.
Transcribe user_ids into screen_names
Almost done We just need to relay those user_ids back to the Twitter API, so we can get the actual account names (i.e. screen_name).
B6 = GET("https://api.twitter.com/1.1/users/lookup.json?user_id="&A6&"",'Control'!E$6)
B7 = GET("https://api.twitter.com/1.1/users/lookup.json?user_id="&A7&"",'Control'!E$6)
Bn = GET("https://api.twitter.com/1.1/users/lookup.json?user_id="&An&"",'Control'!E$6)
Final step PARSE the data in column
B
for the screen_name:
C6 = PARSE(B6,"[0].['screen_name']")
C7 = PARSE(B7,"[0].['screen_name']")
Cn = PARSE(Bn,"[0].['screen_name']")
If you followed these instructions correctly, you should end up with following:
In hindsight, it was super easy… right?
Happy building everyone
P.S.: Notice how column C
contains the bio of the account in question?! Well the data in B
contains a lot more information about users… Go and check it out