If you are only conducting a visual analysis of Twitter – you only want to see the connections between people or hashtags, without seeing the content of the tweets – the you can collect data from twitter directly through Gephi. This method only collects Tweets in real time, and none from the past. You can leave the script running to collect tweets as they are posted. You can collect an unlimited number of future tweets. This tutorial shows you how to setup Gephi to collect and visualize tweets.

This is part of my using Twitter data for research series.

Collecting and visualising tweets in Gephi

1. Installing Gephi

1.1. Gephi is free to use and can be downloaded from https://gephi.org/
1.2. Follow the install instructions. Support with installation can be found here: https://gephi.org/users/support/ 

2. Install the Gephi Twitter Plugin

2.1. Open Gephi and start a new project
2.2. From the menu select Tools > Plugins
2.3. Search for TwitterStreamingImporter from Available Plugins

2.4. Click Install to begin the installation
2.5. Click Next
2.6. Click Continue if you are asked to verify certificate
2.7. Restart Gephi

3. Linking Gephi to your Twitter Account

3.1. From the menu select Window > Twitter Streaming Importer

You should now see a new panel with the Twitter Streaming Importer tools available.

Before we can collect any tweets we need to link Gephi to our twitter account

If you already have a twitter developer account you can skip to part 3.5

3.2. Go to https://developer.twitter.com/en/apply-for-access and log in to your Twitter Account
3.3. Choose ‘Apply for a developer account’

3.4. You will be asked a series of questions about your research. You should answer these fully and honestly.
3.5. Once you have been approved for a developer account click ‘Create an App’ or go to https://developer.twitter.com/en/apps/create
3.6. Complete the form you are presented with. Again you should answer these questions fully and honestly.
3.7. Read and agree to the terms of use by clicking ‘Create’

If you have done this correctly you should now have a working app

3.8. Click on the ‘Keys and tokens’ tab.

We can now link twitter with Gephi.

3.9. Return to Gephi and in the Twitter Streaming Importer window select Credentials.

You will now be asked for your Twitter Keys.

3.10. Copy and paste the API Key and then the API Secret Key into the Twitter Streaming Importer window in Gephi
3.11. Back on the Twitter App page Click ‘Generate’ to produce an ‘Access Token’ and ‘Access Token Secret’
3.12. Copy and paste the ‘Access Token’ and ‘Access Token Secret’s into Gephi and click OK

Your Twitter account is now connected to Gephi – You will not have to do this process again.

4. Importing Tweets with Twitter Streaming Importer

We have a number of options of how and what to search for data from twitter.

4.1 To search for a Hashtag use the ‘Words to Follow’ option. You should enter the search term without the ‘#’
4.2. To search for a person use the ‘Users to Follow’ option. You should enter the search term without the ‘@’

To search for multiple accounts or words at the same time, keep adding them to the list
If you have a really long list of search terms, you can import these by clicking ‘load Query File’

4.3. If you are looking for tweets from one geographical location the select ‘Location to Follow’ and enter the coordinates [click to see how that works].  – Note that this will only download geotagged tweets. – Leave blank to search the whole world.

4.4. Once you have added all the hashtags, users, and locations click ‘Connect’

In the overview view you will now see you graph start to populate:

And in the Data Laboratory view you will see the nodes and edges appearing:

4.5. Once you have collected enough Tweets. Click ‘Disconnect’

You are now ready to process and visualise the data you have collected.

Head to my tutorial on Visualising networks using Gephi for help with that.

Doug Specht is a Reader in Cultural Geography and Communication, a Chartered Geographer (CGeog. FRGS), and Assistant Head of School in the School of Media and Communication at the University of Westminster.

His research examines how knowledge is constructed and codified through digital and cartographic artefacts, focusing on development issues in Latin America and Sub-Saharan Africa, where he has carried out extensive fieldwork. He also writes and researches on pedagogy, and is author of the Media and Communications Student Study Guide.

He speaks and writes on topics of data ethics, development, education and mapping practices at conferences and invited lectures around the world. He is a member of the editorial board at Westminster Papers in Communication and Culture, and the journal Anthropocenes – Human, Inhuman, Posthuman. He is also Chair of the Environmental Network for Central America.