How to identify followers on Twitter

Hey fellow dashdashers :vulcan_salute:

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:

  1. Apply for a Twitter developer account
  2. Get your authentication token
  3. Build your authentication header
  4. GET & PARSE for user_ids of followers
  5. Transcribe user_ids into screen_names

:one: Apply for a Twitter developer account :one:

This step is easy. Navigate to Twitter’s developer page and set yourself up with a developer account :raised_hands:

If you are asked to create an app in the process, please go ahead and do so. Just fill in required fields.

:two: Get your authentication token :two:

Here the authentication process get’s a bit trickier. But bear with me, I’ll guide you through the setup :man_teacher::woman_technologist::man_technologist:

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(""&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 :muscle::astonished:

Your view should look as follows:

:three: Build your authentication header :three:

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 :point_down::grin:

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 :triumph:

:four: GET & PARSE for user_ids of followers :four:

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 =[name]
Accounts following 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(""&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. :mag::nerd_face:

:five: Transcribe user_ids into screen_names :five:

Almost done :grin: 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(""&A6&"",'Control'!E$6)
B7 = GET(""&A7&"",'Control'!E$6)
Bn = GET(""&An&"",'Control'!E$6)

Final step :astonished: 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? :partying_face:

Happy building everyone :construction_worker_man::construction_worker_woman::construction::building_construction:

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 :wink::+1: